C#LINQ过滤列表
发布时间:2020-12-16 10:12:56 所属栏目:百科 来源:网络整理
导读:这是我第一次使用LINQ而我还没有真正得到它. 我试图通过一个例子来理解它,但我需要一些帮助. 我创建了一个类“Person”: class Person{ private string name { get; set; } private int age { get; set; } private bool parent { get; set; } private bool
这是我第一次使用LINQ而我还没有真正得到它.
我试图通过一个例子来理解它,但我需要一些帮助. 我创建了一个类“Person”: class Person { private string name { get; set; } private int age { get; set; } private bool parent { get; set; } private bool child { get; set; } public Person(string name,int age,bool parent,bool child) { this.name = name; this.age = age; this.parent = parent; this.child = child; } } 我创建了一个“人物”列表: people.Add(new Person("Joel",12,false,true)); people.Add(new Person("jana",22,false)); people.Add(new Person("Stefan",45,true,false)); people.Add(new Person("Kurt",25,false)); people.Add(new Person("Sebastian",65,false)); people.Add(new Person("George",14,true)); people.Add(new Person("Noel",50,false)); 现在我想把所有被设定为父母的人都赶出去. var parents = people.Where() 解决方法
linq声明应该是
var parents = people.Where(x => x.parent); 并改变私人布尔父母{get;组; to public bool parent {get;组; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读