标签:
1 code
1 using System; 2 using System.Collections.Generic; 3 using System.IO; 4 using System.Linq; 5 using System.Reflection; 6 using System.Text; 7 using System.Threading.Tasks; 8 9 namespace ConsoleApplication14 10 { 11 public interface IPlus 12 { 13 string age { get; } 14 void Hello(); 15 } 16 class Program 17 { 18 static void Main(string[] args) 19 { 20 Type tpIPlus = typeof(IPlus); 21 Type tpCanClass = typeof(Can); 22 Type tpNoClass = typeof(No); 23 24 if(tpIPlus.IsAssignableFrom(tpCanClass)) 25 { 26 Console.WriteLine(tpCanClass.Name+"实现了接口"+tpIPlus.Name); 27 } 28 else 29 { 30 Console.WriteLine(tpCanClass.Name + "没有实现接口" + tpIPlus.Name); 31 } 32 33 if (tpIPlus.IsAssignableFrom(tpNoClass)) 34 { 35 Console.WriteLine(tpNoClass.Name + "实现了接口" + tpIPlus.Name); 36 } 37 else 38 { 39 Console.WriteLine(tpNoClass.Name + "没有实现了接口" + tpIPlus.Name); 40 } 41 42 Console.ReadKey(); 43 } 44 } 45 46 class Can : IPlus 47 { 48 public string age 49 { 50 get 51 { 52 throw new NotImplementedException(); 53 } 54 } 55 56 public void Hello() 57 { 58 throw new NotImplementedException(); 59 } 60 } 61 class No 62 { 63 64 } 65 }
2 show
C#控制台 判断一个类是否实现了指定的接口 IsAssignableFrom
标签:
原文地址:http://www.cnblogs.com/jinlingzi/p/5982914.html