Skip to content

Instantly share code, notes, and snippets.

@xbotter
Created March 6, 2017 04:42
Show Gist options
  • Save xbotter/8772a1f7fa7f0c1efb0fb31432140b35 to your computer and use it in GitHub Desktop.
Save xbotter/8772a1f7fa7f0c1efb0fb31432140b35 to your computer and use it in GitHub Desktop.
C#协变和逆变示例
using System;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
Two the_two = new Two();
// 协变 逆变
One the_one = AcceptOneReturnTwo(the_two);
}
public static Two AcceptOneReturnTwo(One one){
return (Two)one;
}
}
public class One{ }
public class Two : One{ }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment