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 list of MyData2. I could do it by looping MyData.PropertyList and caching other property values and inserting them to a list of MyData2 like this:
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 features of LINQ or Lambda expression?