我有以下课程:public class Class_A{ public string my_field { get; set; } public int id { get; set; } // etc...}public class Class_B{ public string my_field { get; set; } public Class_A field_A { get; set; } // etc...}public class Class_C{ public string my_field { get; set; } public Class_A field_A { get; set; } // etc...}List<Class_A> list_A = new List<Class_A>(); //and then populate itList<Class_B> list_B = new List<Class_B>(); //and then populate itList<Class_C> list_C = new List<Class_C>(); //and then populate it然后,当我更新某些元素时list_A,例如Class_A old_a, new_a;old_a = list_A.Where("some condition").FirstOrDefault();new_a = new Class_A();//and then initialize itlist_A[list_A.FindIndex(x => x.Equals(old_a))] = new_a;我需要将list_Band 的所有元素(list_C字段Class_A等于)old_a更新为new_a.1. 最好的方法是什么?现在我有以下变体,但我认为它可能会更好:list_B.Where(x => x.Class_A.Equals(old_a)).ForEach(x => x.Class_A = new_a);2. 如果我有此代码,更新所有值的最佳方法是什么?public class Class_D{ public string my_field { get; set; } public List<Class_A> list_A { get; set; } // etc...}List<Class_D> list_D = new List<Class_D>(); //and then populate it
添加回答
举报
0/150
提交
取消