Aşağıdaki kod temsilci kovaryans ve Contavariance
namespace ConsoleApplication1
{
public delegate TResult Function<in T, out TResult>(T args);
class Program
{
static void Main(string[] args)
{
Program pg =new Program();
Function<Object, DerivedClass> fn1 = null;
Function<String, BaseClass> fn2 = null;
fn1 = new Function<object, DerivedClass>(pg.myCheckFuntion)
fn2=fn1;
fn2("");// calls myCheckFuntion(Object a)
pg.myCheckFuntion("Hello"); //calls myCheckFuntion(String a)
}
public DerivedClass myCheckFuntion(Object a)
{
return new DerivedClass();
}
public DerivedClass myCheckFuntion(String a)
{
return new DerivedClass();
}
}
pasajı düşünün neden temsilci çağrı ve normal metot çağrımı çağrısı farklı yöntemler.
Eklenecek bir şey yok. +1 –
Jon Skeet'i yenemezsin! – siride
Benim için çok hızlı :( – VMAtm