It's my first time using LINQ and I don't really get it yet.
I tried to understand it via an example but I need some help.
I created a class "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;
}
}
I created a list of "people":
people.Add(new Person("Joel", 12, false, true));
people.Add(new Person("jana", 22, false, false));
people.Add(new Person("Stefan", 45, true, false));
people.Add(new Person("Kurt", 25, false, false));
people.Add(new Person("Sebastian", 65, true, false));
people.Add(new Person("George", 14, false, true));
people.Add(new Person("Noel", 50, true, false));
Now I would like to get out every person which is set as a parent. But I'm stuck here:
var parents = people.Where()
var parents = people.Where(p => p.parent);
will return all results whereparent
property istrue
. In this case,parent
is abool
type and you can evaluate it without==
orEquals
, but, for non boolean properties you should use the equality comparison.