你如何在Select方法(LINQ)中做别名

时间:2011-06-20 23:25:00

标签: c# linq

我正在尝试使用命名列对字符串列表进行别名:

var providers = EMRRepository.GetProviders().Select(x => x as name);

其中“GetProviders()”返回List<string>

2 个答案:

答案 0 :(得分:22)

它被称为“投影”,只需选择一个新的匿名类型。

var projection = data.Select( x => new { FieldName = x.Property } );

答案 1 :(得分:2)

您希望选择新的匿名类型。

var providers = EMRRepository.GetProviders().Select(x => new { Name = x });