看着这段代码
delegate void StringAction (string s);
class Test
{
static void Main()
{
StringAction sa = new StringAction (ActOnObject);
sa ("hello");
}
static void ActOnObject (object o)
{
Console.WriteLine (o); // hello
}
}
由于逆变性,此代码是否有效?( MoreDerivedRef <== LessDerivedRef )
或者因为
(与逆变无关) - 在 c# 中,我可以执行类似的ActOnObject (object o)
方法ActOnObject ("lalala")