转换foreach到linq
我现在有个foreach语句,想把他转成LINQ,试了几次都是错的,故请帮忙:
List<string> dataColumnName = new List<string>();
foreach (DataColumn dataColumn in columnCollection)
dataColumnName.Add(dataColumn.ColumnName);
columnCollection是一个DataColumnCollection,想要返回他的每列的列名的集合
------解决方案--------------------dataColumnName = columnCollection.Cast<DataColumn>().Select(x => x.ColumnName).ToList();
------解决方案--------------------
columnCollection.ForEach(s => dataColumnName.Add(s.ColumnName));