Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.89 KB | None | 0 0
  1. using System;
  2.  
  3. namespace test
  4. {
  5.     class Program
  6.     {
  7.         class C
  8.         {
  9.             public override string ToString()
  10.             {
  11.                 return "C";
  12.             }
  13.         }
  14.         class D : C
  15.         {
  16.             public override string ToString()
  17.             {
  18.                 return "D";
  19.             }
  20.         }
  21.  
  22.         static void Main(string[] args)
  23.         {
  24.             Action<C> actc = ShowC;
  25.             Action<D> actd = actc;
  26.             Console.WriteLine("get "+(actd is Action<C>)); //true
  27.  
  28.             //Action<C> actc2 = actd; //所以這邊是真的沒救,沒辦法從 Action<D> 轉回 Action<C> 嗎?
  29.             Console.ReadLine();
  30.         }
  31.         private static void ShowC(C c)
  32.         {
  33.             Console.WriteLine(c);
  34.         }
  35.         private static void ShowD(D d)
  36.         {
  37.             Console.WriteLine(d);
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement