c# - LINQ - GROUP BY on object to create string -
so have object called version
it contains list of states, , list of dates
i want first:
- group states, , create string of states (comma separated)
- group dates, , create string of dates (comma separated)
here have tried:
date = version.states.groupby(v => v.date).select(vh => vh.tostring()).tostring(), state = version.states.groupby(s => s.state).select(st => st.tostring()).tostring()
can me out here?
try this:
var states = version.states.aggregate(string.empty, (c, state) => c + state.tostring() + ",").trimend(new []{','}); var dates = version.dates.aggregate(string.empty, (c, date) => c + date.tostring() + ",").trimend(new []{','});
Comments
Post a Comment