I have the following two classes:
class MyData { public List<string> PropertyList { get; private set;} public string PropertyB { get; set; } public string PropertyC { get; set; } } class MyData2 { public string PropertyA { get; set;} public string PropertyB { get; set; } public string PropertyC { get; set; } }
If I have an instance of MyClass, I need to convert it to a MyData2 list. I could do this by looping MyData.PropertyList and caching the other property values โโand entering them into the MyData2 list as follows:
string propertyB = myData.PropertyB; string propertyC = myData.PropertyC; List<MyData2> myData2List = new List<MyData>(); foreach(string item in myData.PropertyList) { myData2List.Add(new myData2() { item, propertyB, propertyC }); }
Not sure if this can be done with .Net 3.5 LINQ or Lambda expression functions?
c # lambda linq
David.Chu.ca Jul 24. '09 at 6:29 2009-07-24 06:29
source share