Created
March 6, 2017 04:42
-
-
Save xbotter/8772a1f7fa7f0c1efb0fb31432140b35 to your computer and use it in GitHub Desktop.
C#协变和逆变示例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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