I have an object "MyObject
" with the properties (all string): "PropA
", "PropB
" and "PropC
".
var List = new List();
I add some object in this list with the following value :
List.Add(new MyObject { PropA = "AA", PropB = "1", PropC = "TT"});
List.Add(new MyObject { PropA = "AA", PropB = "1", PropC = "TT"});
List.Add(new MyObject { PropA = "AA", PropB = "1", PropC = "TT"});
List.Add(new MyObject { PropA = "BB", PropB = "1", PropC = "TT"});
List.Add(new MyObject { PropA = "BB", PropB = "1", PropC = "TT"});
With linq, I'd like for each different "PropA
" keep the first record but set to string.Empty the other. The result I'd like is a List with these values :
MyObject { PropA = "AA", PropB = "1", PropC = "TT"}
MyObject { PropA = "", PropB = "", PropC = "TT"}
MyObject { PropA = "", PropB = "", PropC = "TT"}
MyObject { PropA = "BB", PropB = "1", PropC = "TT"}
MyObject { PropA = "", PropB = "", PropC = "TT"}
I did with foreach but it's may be a bit cleaner in Linq, but the order of the result must be kept.