Let’s say I have a class like:
public class Foo
{
public string Title {get;set;}
}
Now, let’s assume I have a public List<Foo> myList which I want to filter by Linq as so:
var x = myList.Where(f => f.Title == myValue);
Everything is nice and clear until now.
But how can access the property by variable? Something like:
string myProperty = "Title";
var x = myList.Where(f => f.myProperty == myValue);
You can write an extension method
and use it like this