c# - Convert List of object into another List of object -
i have list as
class vachel { int id{get;set;} int vachelid {get;set;} string title {get;set;} } list of vachel as
id vachelid title 1 2 bus 1 3 truck 2 4 cycle 2 5 bike 2 5 bick and want convert list<vachel> list<result>
class result { int id{get;set;} string vachelid {get;set;} string title {get;set;} } and result must as
id vachelid title 1 2,3 bus,truck 2 4,5 cycle,bike,bick i tried as
list<vachel> v = getlist(); list<result> r = null; r = v.groupby(x=> new{x.vachelid}) .select ( x=> new result { id =x.key.id, vachelid =x.firstordefault().vachelid, title =x.firstordefault().title } ).tolist(); here know want put instead of .firstordefault().vachelid , .firstordefault().title don't know do.
r = v.groupby(x => x.id) .select(g => new result(){ id = g.key, vachelid = string.join(",", g.select(x => x.vachelid).distinct()), title = string.join(",", g.select(x => x.title).distinct()), }).tolist();
Comments
Post a Comment