Contravariant Delegates Value Types

Posted by ChloeRadshaw on Stack Overflow See other posts from Stack Overflow or by ChloeRadshaw
Published on 2010-06-09T08:45:35Z Indexed on 2010/06/09 8:52 UTC
Read the original article Hit count: 252

Filed under:

Can anyone shed light on why contravariance does not work with C# value types?

The below does not work

private delegate Asset AssetDelegate(int m);

internal string DoMe()
{
    AssetDelegate aw = new AssetDelegate(DelegateMethod);
    aw(32);
    return "Class1";
}

private static House DelegateMethod(object m)
{
    return null;
}

© Stack Overflow or respective owner

Related posts about c#