首页 > 代码库 > 返回类型协变和参数类型逆变

返回类型协变和参数类型逆变

    class Animal    { }    class Dog : Animal    { }    class Program    {        static void Main(string[] args)        {            //返回类型协变            Func<Animal, Animal> s = doThing;            //参数类型逆变            Action<Dog> s2 = doThing2;        }                static Dog doThing(Animal x)        {            return null;        }        static void doThing2(Animal x)        {        }    }

  

返回类型协变和参数类型逆变