标签:
1 code
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Reflection; 5 using System.Text; 6 using System.Threading.Tasks; 7 8 namespace ConsoleApplication10 9 { 10 class Program 11 { 12 static void Main(string[] args) 13 { 14 Type tp = typeof(Test2); 15 MethodInfo [] methods =tp.GetMethods(); 16 foreach (var item in methods) 17 { 18 Console.WriteLine(item.Name); 19 } 20 Console.ReadKey(); 21 } 22 } 23 class Test1 24 { 25 //GetMethods看不到这个 26 private void NoGet() 27 { 28 29 } 30 //GetMethods看得到这个 31 public void CanGet() 32 { 33 34 } 35 } 36 class Test2:Test1 37 { 38 private int _age; 39 private string _name; 40 41 public int Age 42 { 43 get 44 { 45 return _age; 46 } 47 48 set 49 { 50 _age = value; 51 } 52 } 53 54 public string Name 55 { 56 get 57 { 58 return _name; 59 } 60 61 set 62 { 63 _name = value; 64 } 65 } 66 //一个函数 67 public void AMethod() 68 { 69 70 } 71 } 72 }
2 show
C#控制台 getmethods获取一个类及父类中共有的方法名
标签:
原文地址:http://www.cnblogs.com/jinlingzi/p/5982830.html