using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SimpleVariance
{
    class Animal { }
    class Cat: Animal { }

    class Program
    {
        // To understand what the new CoVariance and ContraVariance code does for you
        // Try deleting or adding the words out and in from the following 2 lines of code:
        delegate T Func1<out T>();
        delegate void Action1<in T>(T a);
        static void Main(string[] args)
        {
            Func1<Cat> cat = () => new Cat();
            Func1<Animal> animal = cat;

            Action1<Animal> act1 = (ani) => { Console.WriteLine(ani); };
            Action1<Cat> cat1 = act1;

            Console.WriteLine(animal());
            cat1(new Cat());
        }

    }
}

相关文章:

  • 2021-08-08
  • 2021-08-03
  • 2021-11-24
  • 2021-04-09
  • 2022-02-02
  • 2022-03-09
  • 2021-07-03
  • 2021-10-21
猜你喜欢
  • 2022-02-02
  • 2021-11-20
  • 2021-11-20
  • 2021-12-28
  • 2021-07-10
  • 2021-05-17
  • 2021-12-04
相关资源
相似解决方案