views:

107

answers:

1

I have the following code:

IEqualityComparer<WorkItem> comparer = 
     new LambdaComparer<WorkItem>((item1, item2) => item1.Type == item2.Type);

var someVar = Pad.Distinct(comparer);

(The idea is to get 1 of each type)
And it is giving the following error message:

The type arguments for method 'System.Linq.Enumerable.Distinct
(System.Collections.Generic.IEnumerable, 
System.Collections.Generic.IEqualityComparer)' cannot be inferred 
from the usage. Try specifying the type arguments explicitly.   490

I have done something similar and it works just fine:

Pad = new Dictionary<WorkItem, Canvas>(new LambdaComparer<WorkItem>((x, y) => x.Id == y.Id, x => x.Id));

So I don't think it is my LamdaComparer class.

Any ideas on how to fix this? (I guess I could just do a ForEach and get the distinct manually.)

+1  A: 

Since Pad is a Dictionary, you need an IEqualityComparer<KeyValuePair<WorkItem, Canvas>>.

So, basically, the typeparams of the comparer you're passing to Distinct are insufficient. :(

So you're right, based on the code provided, it looks like LambdaComparer is not the problem. You just need to define your "comparer" variable differently.

Sapph
Absolutely right! Thanks.
Vaccano