如何使用linq对列表中的特定字段进行分组

时间:2016-05-24 12:51:10

标签: c# linq

我从服务中获取列表。但在那个特定的服务中我只需要2个字段值。我写了一个select查询,但它没有返回所有列表。

var TranslResult = serviceResponse.Result.ToList();

selectedReasons = TranslResult.Select(x => new TranslationContentEntity
{
    ContentId= x.ContentId,
    ContentType= x.ContentType
});

但我得到以下结果, enter image description here

1 个答案:

答案 0 :(得分:2)

你可以使用这样的匿名类:

selectedReasons = TranslResult.Select(x => new 
{
     ContentId= x.ContentId,
     ContentType= x.ContentType
});