PropertyInfo、FieldInfo、MemberInfo的区别
2024-10-07 06:50:38
public class TestClass
{
private int a = ;//私有一律获取不到
public int b
{
get { return ; }
set { value = ; }
}
public int c = ;
} 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 fil)//仅能获取到c字段(输出c)
{
Console.WriteLine("MemberInfo: "+ item.Name );
}
}
问题:
[多选] 哪个对象的类型来源于MemberInfo类?()
A . FieldInfo class
B . MethodInfo class
C . Assembly class
D . Type cla
参考答案: A, B, D
参考
最新文章
- 转-Apache的Order Allow,Deny 详解
- wordpress(三)wordpress手动更新
- Visual Studio 2013 Nuget控制台无法找到程序包
- JVM 内存
- HDU 2222 Keywords Search(AC自动机入门)
- NSKeyedArchiver 类 格式
- Git的优势
- angularjs2 学习笔记(二) 组件
- vim插件配置(一)
- Chapter 1 Securing Your Server and Network(1):选择SQL Server运行账号
- Linux -atime、mtime、ctime
- H3C数据中心虚拟化解决方案技术白皮书
- 重写,string创建内存问题
- Linux下redis的安装及配置
- MySql数据库连接池专题
- Activity启动模式 Tasks和Back Stack
- mysql 通过慢查询日志查写得慢的sql语句
- 【转】Python中的eval()、exec()及其相关函数
- cf相关命令
- jquery ajax 设置请求头header 参数