c# - How do i convert from one collection to another -
i have:
ienumerable<foo> foolist
and want convert to:
ienumerable<bar> barlist
is there linq / lambda solution move 1 other
both objects (foo , bar) have simple properties going convert. example:
bar.myyear = foo.year
they each have 6 properties
you can do:
ienumerable<bar> barlist = foolist.select( foo => new bar(foo.year)); // add other construction requirements here...
enumerable.select projection function, perfect type conversions. help:
projects each element of sequence new form.
edit:
since bar
doesn't have constructor (from comments), can use object initializers instead:
ienumerable<bar> barlist = foolist.select( foo => new bar() { year = foo.year, month = foo.month // add other properties needed here... });
Comments
Post a Comment