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

StackOverflow https://stackoverflow.com/questions/13822840

  •  07-12-2021
  •  | 
  •  

Question

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.

Was it helpful?

Solution

You could cast explicitly:

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top