I have the following two classes:
class MyData {
public List PropertyList { get; private set;}
public string PropertyB { get; set; }
publ
It's nice and easy. You want to do something based on every item (a string) in a particular list, so make that the starting point of your query expression. You want to create a new item (a MyData2
) for each of those strings, so you use a projection. You want to create a list at the end, so you call ToList()
to finish the job:
var myData2List = myData.PropertyList
.Select(x => new MyData2 {
PropertyA = x,
PropertyB = myData.PropertyB,
PropertyC = myData.PropertyC })
.ToList();