标签:
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 PropertyInfo [] properties =tp.GetProperties(); 16 foreach (var item in properties) 17 { 18 Console.WriteLine(item.Name); 19 } 20 Console.ReadKey(); 21 } 22 } 23 class Test1 24 { 25 //私有字段 26 private int _ziDuanBase; 27 //共有属性 28 public int ZiDuanBase 29 { 30 get 31 { 32 return _ziDuanBase; 33 } 34 35 set 36 { 37 _ziDuanBase = value; 38 } 39 } 40 41 42 43 //GetMethods看不到这个 44 private void NoGet() 45 { 46 47 } 48 //GetMethods看得到这个 49 public void CanGet() 50 { 51 52 } 53 } 54 class Test2:Test1 55 { 56 //私有字段 57 private int _age; 58 //共有字段 59 public string _name; 60 61 //公共属性 62 public int Age 63 { 64 get 65 { 66 return _age; 67 } 68 69 set 70 { 71 _age = value; 72 } 73 } 74 75 //私有属性 76 private string Name 77 { 78 get 79 { 80 return _name; 81 } 82 83 set 84 { 85 _name = value; 86 } 87 } 88 //一个函数 89 public void AMethod() 90 { 91 92 } 93 } 94 }
2 show
C#控制台 getproperties获取一个类及其父类中共有的属性名
标签:
原文地址:http://www.cnblogs.com/jinlingzi/p/5982835.html