hi all,
In my 'Person' class, I have some fields like 'firstname','lastname','nickname' and so on.
I want to write code to search dynamically, sometimes by 'firstname' and sometimes by 'nickname' field.
In the regular way, the code will be:
If(SearchBy == "firstname")
{
Person result = ListOfPerson.Where(p => p.firstname== "exp").FirstOrDefault();
}
else If(SearchBy == "nickname")
{
Person result = ListOfPerson.Where(p => p.nickname== "exp").FirstOrDefault();
}
But the code I want to write, should be like this:(to save the if each time)
Object someVariable = "firstname";
Person result = ListOfPerson.Where(p => p.someVariable == "exp").FirstOrDefault();
Can anyone Know if it's possible?