【发布时间】:2011-09-21 02:59:25
【问题描述】:
我可以在函数中使用匿名类型作为返回类型,然后将返回值填充到某种数组或集合中,同时还向新数组/集合添加附加字段吗?原谅我的伪代码...
private var GetRowGroups(string columnName)
{
var groupQuery = from table in _dataSetDataTable.AsEnumerable()
group table by new { column1 = table[columnName] }
into groupedTable
select new
{
groupName = groupedTable.Key.column1,
rowSpan = groupedTable.Count()
};
return groupQuery;
}
private void CreateListofRowGroups()
{
var RowGroupList = new List<????>();
RowGroupList.Add(GetRowGroups("col1"));
RowGroupList.Add(GetRowGroups("col2"));
RowGroupList.Add(GetRowGroups("col3"));
}
【问题讨论】:
-
返回一个元组,C# 7 特性。你可以在这里阅读更多:blogs.msdn.microsoft.com/dotnet/2016/08/24/…
标签: c# linq generics collections