P
puzzlecracker
Do delegates don't respect polymorphisms -- why?
say in this example:
using System;
public delegate string FirstDelegate (int x);
abstract class Base
{
public abstract string Foo(int );
public void Dispatch()
{
FirstDelegate del=new FirstDelegate (Foo);
del(5);
}
}
class Derived
{
public override string Foo(int x)
{
return " "+x;
}
}
class Runner
{
public static void Main()
{
Derived d=new Derived();
d.Dispatch(); //trys to delegate bases
}
}
The same thing happens when Base is NOT abstract class and Foo is
declared as virtual....
Is there a rule don't mix delegates and runtime polymorphism???
say in this example:
using System;
public delegate string FirstDelegate (int x);
abstract class Base
{
public abstract string Foo(int );
public void Dispatch()
{
FirstDelegate del=new FirstDelegate (Foo);
del(5);
}
}
class Derived
{
public override string Foo(int x)
{
return " "+x;
}
}
class Runner
{
public static void Main()
{
Derived d=new Derived();
d.Dispatch(); //trys to delegate bases
}
}
The same thing happens when Base is NOT abstract class and Foo is
declared as virtual....
Is there a rule don't mix delegates and runtime polymorphism???