PropertyInfoFieldInfoMemberInfo的区别
Posted Mentalflow
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PropertyInfoFieldInfoMemberInfo的区别相关的知识,希望对你有一定的参考价值。
public class TestClass { private int a = 1;//私有一律获取不到 public int b { get { return 2; } set { value = 2; } } public int c = 3; } public static void TestMethod() { TestClass test = new TestClass(); PropertyInfo[] pro = test.GetType().GetProperties(); FieldInfo[] fil = test.GetType().GetFields(); MemberInfo[] men = test.GetType().GetMembers(); foreach (var item in pro)//仅能获取到b属性(输出b=2) { Console.WriteLine("PropertyInfo: " + item.Name +"=" + item.GetValue(test, null)); } foreach (FieldInfo item in fil)//仅能获取到c字段(输出c=2) { Console.WriteLine("FieldInfo: " + item.Name + "=" + item.GetValue(test)); } foreach (MemberInfo item in men)//仅能获取到成员元素据 { Console.WriteLine("MemberInfo: "+ item.Name ); } }
问题:
[多选] 哪个对象的类型来源于MemberInfo类?()
A . FieldInfo class
B . MethodInfo class
C . Assembly class
D . Type cla
参考答案: A, B, D
参考
以上是关于PropertyInfoFieldInfoMemberInfo的区别的主要内容,如果未能解决你的问题,请参考以下文章