比较相同类的实例并用新值更新旧实例

比较相同类的实例。

public class Student()
{
    public string Name {get; set;}
    public string Hobby {get; set;}
    public string Country {get; set;}
}

Student old = new Student { Name = "A", Hobby = "Swim", Country = "HK" };
Student new = new Student { Name = "A", Hobby = "Jog", Country = "US" };

如果旧的和新的相等,则比较,否则,替换不同的类的每个字段。比如将旧值更新为新值。

If(old != new)
{
    UpdateOldWithNew(old, new);
}

转载请注明出处:http://www.smbzepe.com/article/20230331/1761404.html