开发者

Linq: How to make this work

I have this Linq statement:

List<string> phoneNumbers = from t
                            in fixedLineData
                            select t.phoneNumber.Distinct();

Basically what I want is a distinct list of strings sent b开发者_JAVA百科ack from the LINQ query.

Is this possible?


Make it

  var phoneNumbers =
      (from t in fixedLineData 
      select t.phoneNumber)
      .Distinct().ToList();

But you might as well skip the query-syntax:

 var phoneNumbers =
      fixedLineData 
      .Select (t => t.phoneNumber)
      .Distinct()
      .ToList();

The .ToList() will make the resulting type IList<string>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜