I have an object of objects where one property can have duplicate values i am trying to find an algorithm to loop through the object and create a new list of object having group by duplicate values.
how do i loop through an object and create a new object in C# i have a view model eg:
pViewModel {
public itemFullName {get;set;}
public Item Item{get;set;}
public string itemAddress {get;set;}
public string itemCountry {get;set;}
public string addressId {get;set;}
}
public Item{
public int itemId{get;set;}
}
I want to create a new object after finding matching fullname but different id so my new object will have a list of itemFullName, item.itemid(pipedelimited values for all the items in the previous list),itemaddress, itemCountry in it.
Any help will be awesome. thank you
someone pointed out to this
var itemsAndIds = list
.GroupBy(m => m.itemFullName, m => m.Item.itemId)
.Select(g => new {ItemFullName = g.Key, ItemIds = string.Join("|", g)})
but now I need the new properties added to this object