The question and answer of converting a class to another list of class is cool. How about to convert a list of MyData to another list of MyData2? For example:
List<MyData> list1 = new List<MyData>();
// somewhere list1 is populated
List<MyData2> list2;
// Now I need list2 from list1. How to use similar LINQ or Lambda to get
list2 = ... ?
Here I tried this but I cannot figure out the complete codes:
list2 = (from x in list1 where list1.PropertyList == null
select new MyData2( null, x.PropertyB, x.PropertyC).
Union (
from y in list1 where list.PropertyList != null
select new MyData2( /* ? how to loop each item in ProperyList */
y.PropertyB, y.PropertyC)
).ToList();
where MyData2 has a CTOR like (string, string, string).