nella mia richiesta, ho il codice simile al seguente:ambiguo C# chiamata di metodo con i delegati
class Program
{
static void Main(string[] args)
{
Method(uri => Task.FromResult(uri));
}
static void Method(Func<Uri, Uri> transformer)
{
throw new NotImplementedException();
}
static void Method(Func<Uri, Task<Uri>> transformer)
{
throw new NotImplementedException();
}
}
Come previsto, l'esecuzione di questo codice chiama il secondo sovraccarico del 'Metodo', quella in attesa di un funzione di delegato che restituisce un compito. Tuttavia, se cambio il codice per evitare di utilizzare il metodo anonimo in Main:
class Program
{
static void Main(string[] args)
{
Method(Method2);
}
static Task<Uri> Method2(Uri uri)
{
return Task.FromResult(uri);
}
static void Method(Func<Uri, Uri> transformer)
{
throw new NotImplementedException();
}
static void Method(Func<Uri, Task<Uri>> transformer)
{
throw new NotImplementedException();
}
}
Il compilatore C# ora si lamenta che la mia chiamata a 'Metodo' è ambiguo. Cosa mi manca?
non si passa un Uri a Method2. –
@ SamAxe lui non intende. Sta provando a convertire un * metodo group * ('Method2') in un delegato (' Func> ') –
dcastro
Probabilmente perché' TResult' in 'Func' è covariante. –
haim770