So, I started to build a small test application to test lambda expressions. I found several examples here and elsewhere but I just don't get them.
Can anybody explain my how to build an expression by using textboxes or any other variables?
My Test List
List<People> lPeople = new List<People>
{
new People { Name= "Jean", LastName = "Borrow", Age= 21 } ,
new People { Name= "Dean", LastName = "Torrow", Age= 20 }
};
Working lambda Expression
IEnumerable<People> result = lPeople.Where(p => p.Age < 21);
dgv_1.DataSource = result.ToList();
dgv_1.Update();
How can I build the expressions dynamically?
Something like lPeople.Where(p => p.LastName == Textbox.Text);
(which of course doesn't work)
Thanks!
Edit: Added some code to the solution below
Int32 iAge;
Boolean bSuc = Int32.TryParse(tb_filter_age.Text, out iAge);
if (!bSuc)
{
iAge = 0;
}