引用System.Reflection的 MemberInfo、MethodInfo 获得一个类的成员。

using System;
using System.Reflection;

public class yuping
{
}

public class test
{
 static void Main(){
  Console.WriteLine("List  class member of yuping");

 
 MemberInfo[] class_members = typeof(yuping).GetMembers();  //成员;
 foreach (MemberInfo m in class_members)
 {
  Console.WriteLine(m.ToString());
 }

 MethodInfo[] class_methods = typeof(yuping).GetMethods();   //方法;
 foreach (MethodInfo f in class_methods)
 {
  Console.WriteLine(f.ToString());
 }

 }

}

为设置和获取属性的值,C# 在内部隐性包含了属性 get 和 set accessors 表示为 get_属性名() 和 set_属性名() 方法。

相关文章:

  • 2022-12-23
  • 2021-08-19
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
  • 2022-02-28
  • 2022-12-23
  • 2021-05-24
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-18
  • 2021-10-01
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案