I’m trying to write a simple Lambda expression in C#:
int numElements = 3;
string[]firstnames = {"Dave", "Jim", "Rob"};
string[]lastnames = {"Davidson", "Jameson", "Robertson"};
List<Person> people = new List<Person>();
for(int i = 0 ; i < numElements; i++)
{
people.Add(new Person { FirstName = firstnames[i], LastName = lastnames[i] });
}
bool test = people.Contains(p => p.FirstName == "Bob");
My understanding of Lambda expressions and how they work is still a little shady and I miffed as to why this will not work…I’m trying to find out if a list contains a name…
Are you looking for:
Or are you mixing Rob and Bob?