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>
精彩评论