不说多少,直接上代码:
1 namespace is_as 2 { 3 class Program 4 { 5 static void Main(string[] args) 6 { 7 object n = run(2); 8 if (n is int) 9 { 10 Console.WriteLine((int)n); 11 } 12 else if (n is string) 13 { 14 Console.WriteLine(n.ToString()); 15 } 16 a u = new a(); 17 object n2 = u; 18 b k = n2 as b; 19 } 20 public static object run(int i) 21 { 22 if (i == 1) 23 { 24 int k = 2; 25 return k; 26 } 27 else 28 { 29 string ddd = "jkj"; 30 return ddd; 31 } 32 } 33 } 34 } 35 class a 36 {} 37 class b 38 { }
转自如鹏网络课程------个人课后笔记,仅供参考