using System;
using System.Reflection;
namespace 反射
{
class Myclass
{
private int myProperty;
public int MyProperty
{
get;
set;
}
}
class Program
{
static void Main(string[] args)
{
try
{
Type myType = typeof(Myclass);
PropertyInfo myProinfo = myType.GetProperty("MyProperty");
Console.WriteLine(myType.Name);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
using System.Reflection;
namespace 反射
{
class Myclass
{
private int myProperty;
public int MyProperty
{
get;
set;
}
}
class Program
{
static void Main(string[] args)
{
try
{
Type myType = typeof(Myclass);
PropertyInfo myProinfo = myType.GetProperty("MyProperty");
Console.WriteLine(myType.Name);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
本文介绍了一个使用C#反射机制获取类属性信息的例子。通过反射可以动态地获取类的类型,并读取指定属性的详细信息。
1710

被折叠的 条评论
为什么被折叠?



