I am trying to write a LINQ query which will return true if there are multiple objects which have a property with the same value.
Here is what I have come up with so far:
Formatters.Where(Function(f As DataModel.Formatter) _
Formatters.Select(Function(f2 As DataModel.Formatter) f2.Name.ToLower()).Contains(f.Name.ToLower())).Count > 1
However the above always returns true as lo开发者_如何学JAVAng as their are more then 1 elements in the list, can someone please give me a hand with this?
Here it is in C#. Should be easy to convert to VB.NET, but I don't have a visual studio install handy:
var query = from g in Formatters.GroupBy( f => f.Name, StringComparer.OrdinalIgnoreCase)
where g.Count () > 1
select g;
if (query.Any()){
Console.WriteLine("Duplicate names!");
}
精彩评论