Adam Nathan
Adam Nathan

Reputation: 158

Using Method Group gives me The call is ambiguous between the following methods or properties:

I want to call a simple method group in Linq but I receive this error.

The call is ambiguous between the following methods or properties: 'System.Linq.Enumerable.Select<string,int>(System.Collections.Generic.IEnumerable<string>, System.Func<string,int>)' and 'System.Linq.Enumerable.Select<string,int>(System.Collections.Generic.IEnumerable<string>, System.Func<string,int,int>)'

var num = new [] { "12345", "5432" };

num.Select(Convert.ToInt32);

I understand that there is ambiguity between which method to call. My question is however, is there a way of specifying the signature without calling the method normally. I want to save typing by not having to use lambda expressions.

Thanks.

Upvotes: 1

Views: 1314

Answers (1)

ajukraine
ajukraine

Reputation: 561

You could cast explicitly:

num.Select((Func<String, Int32>)Convert.ToInt32);

Upvotes: 2

Related Questions