C
codefragment
Hi
I just had a bit of a surprise, I expected this to work!
public class A
{
}
public class AChild : A
{
}
public class B
{
}
public class BChild : B
{
}
public delegate A TheDelegate(B b);
private AChild Func(BChild b)
{
return null;
}
public void CallDelegate()
{
TheDelegate a= new TheDelegate(Func);
}
Of course it doesn't work because Func uses child classes of the kinds
used in the
delegate.
Why doesn't this work, if I made a delegate like this:
public delegate object TheDelegate(object b);
I'd expect any function that took any class and returned any class to
work.
However, thats the state of affairs so any way of doing what I want to
do here? i.e. call
Func later?
Ta
C
I just had a bit of a surprise, I expected this to work!
public class A
{
}
public class AChild : A
{
}
public class B
{
}
public class BChild : B
{
}
public delegate A TheDelegate(B b);
private AChild Func(BChild b)
{
return null;
}
public void CallDelegate()
{
TheDelegate a= new TheDelegate(Func);
}
Of course it doesn't work because Func uses child classes of the kinds
used in the
delegate.
Why doesn't this work, if I made a delegate like this:
public delegate object TheDelegate(object b);
I'd expect any function that took any class and returned any class to
work.
However, thats the state of affairs so any way of doing what I want to
do here? i.e. call
Func later?
Ta
C