this.NameList = new ObservableCollection<Name>(); List<Others> others1 = new List<Others>(); others1.Add(new Others() { Company = "Company1", School = "School1" }); others1.Add(new Others() { Company = "Company1", School = "School1" }); others1.Add(new Others() { Company = "Company1", School = "School1" }); List<Others> others2 = new List<Others>(); others2.Add(new Others() { Company = "Company2", School = "School2" }); others2.Add(new Others() { Company = "Company2", School = "School2" }); others2.Add(new Others() { Company = "Company2", School = "School2" }); List<Others> others3 = new List<Others>(); others3.Add(new Others() { Company = "Company3", School = "School3" }); others3.Add(new Others() { Company = "Company3", School = "School3" }); others3.Add(new Others() { Company = "Company3", School = "School3" }); this.NameList.Add(new Name() { FirstName = "Jacob", LastName = "Deng", Others = others1 }); this.NameList.Add(new Name() { FirstName = "David", LastName = "Xu", Others = others2 }); this.NameList.Add(new Name() { FirstName = "Helen", LastName = "Liu", Others = others3 });
现在的需求是,如果通过Linq 修改this.NameList,把Others里面school为school2和school3的项都删掉。
修改完之后的结果可以下面这段代码的运行效果一样,谢谢,我本来想放点金币什么的,但是我真的没有了,求帮忙,谢谢
1 others1.Add(new Others() { Company = "Company1", School = "School1" }); 2 others1.Add(new Others() { Company = "Company1", School = "School1" }); 3 others1.Add(new Others() { Company = "Company1", School = "School1" }); 4 5 List<Others> others2 = new List<Others>(); 6 List<Others> others3 = new List<Others>(); 7 8 this.NameList.Add(new Name() { FirstName = "Jacob", LastName = "Deng", Others = others1 }); 9 this.NameList.Add(new Name() { FirstName = "David", LastName = "Xu", Others = others2 }); 10 this.NameList.Add(new Name() { FirstName = "Helen", LastName = "Liu", Others = others3 });
你的修改用的什么 list可以通过索引删除 可以通过Remove 可以通过RemoveAll