I have this object :
public class MyObject
{
public int Id { get; set; }
public string FieldA { get; set; }
public string FieldB { get; set; }
public string FieldC { get; set; }
public string FieldD { get; set; }
}
I have an IList<> of this object :
IList<MyObject> MyListObject = new List<MyObject>();
I do a Linq query on it :
var result = (from p in MyListObject where p.FieldC == "Test" select p.FieldA);
In this case, I return "p.FieldA" but sometimes I need to return "p.FieldB". I'd like put the name of the field (FieldA or FieldB) in a variable like this
var myvar = "FieldB"
var result = (from p in MyListObject where p.FieldC == "Test" select p.????);
How use myvar content (FieldB) as field name in the Linq query ?
Thanks,