c# - select object which matches with my condition using linq -
i have list of type person has 3 properties id, name, age
var per1 = new person((1, "john", 33); var per2 = new person((2, "anna", 23); var persons = new list<person>(); persons.add(per1); persons.add(per2);
using linq want select person age matched input, example 33.
i know how use dont know how select object matches condition.
for 1 match:
var match = persons.single(p => condition);
for many matches, use persons.where(condition)
. there many variants of picking 1 person, such firstordefault, first, last, lastordefault, , singleordefault. each has different semantics depending on want.
Comments
Post a Comment