【发布时间】:2014-07-03 16:35:07
【问题描述】:
有一个简单的模型:
public class SimpleClass
{
public string prop1 { get; set; }
public string prop2 { get; set;}
}
还有一个集合:
List<SimpleClass> myCollection = new List<SimpleClass>();
我想做以下事情:
var headerCollection = new List<string>();
foreach(var item in myCollection)
{
headerCollection.add(item.prop1);
headerCollection.add("Total");
headerCollection.add("Date");
//...
headerCollection.add(item.prop2);
}
但我需要对对象使用 linq。
我试过了:
var modifiedHeaders = myCollection
.Select(item => new[] { item.CON_DESCRIPCION, "Total", "Date", item.prop2 });
但它会生成一个类型的集合:List<string[]>。如何解决?
【问题讨论】:
标签: c# linq linq-to-objects