Why does this not work? Do I not understand delegate covariance correctly?
public delegate void MyDelegate(object obj)
public class MyClass
{
public MyC
The MyDelegate
type declares that you can pass any kind of object in. However, MyMethod
only takes objects of type SomeObject
. What happens if I try to invoke the delegate passing a different kind of object: _delegate("a string object")
? According to the declaration of MyDelegate
, this should be allowed, but your function MyMethod
can't actually receive a string argument.