I'm doing a simple GroupBy taking the First element but I want to modify one of the property of each result.
class M
{
public string Name {get; set;}
public int NOfPeopleWithTheSameName {get; set;}
public string P1 {get; set;}
public string P2 {get; set;}
public string P3 {get; set;}
public string P4 {get; set;}
public string P5 {get; set;}
}
List<M> myList = GetMyList();
var l2 = myList
.GroupBy(m => m.Name)
.Select(group => new M { Name = group.Key, NOfPeopleWithTheSameName = group.Count() });
This is pretty easy, but this way is not the best if the class has many properties (since every property value should be copied to the new one)? I should copy them one by one.
I would like to simply take the element and change the property NOfPeopleWithTheSameName