首页 新闻 赞助 找找看

如何通过LINQ或者其他方式取得不符合条件的子项目

0
[已解决问题] 解决于 2017-03-18 18:58
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 });
五月℃夏到了的主页 五月℃夏到了 | 初学一级 | 园豆:17
提问于:2016-05-07 17:23
< >
分享
最佳答案
0

你的修改用的什么 list可以通过索引删除 可以通过Remove 可以通过RemoveAll

奖励园豆:5
大杯美式不加糖不加奶 | 小虾三级 |园豆:994 | 2016-05-09 09:10
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册