class TestField { private int i=12; protected string sabc = "a"; public DateTime dt = DateTime.Now;
static void Main() { TestField tf = new TestField(); foreach (FieldInfo fi in tf.GetType().GetFields(BindingFlags.Public|BindingFlags.Instance|BindingFlags.NonPublic)) { object o = fi.GetValue(tf); Console.WriteLine("name:{0}==>value:{1}", fi.Name, o.ToString()); } } }思归的做法,强
//同意楼上啊!用反射 Type ty = typeof(Form); PropertyInfo[] py = ty.GetProperties(); foreach (PropertyInfo aa in ty) { aa.Name;//这就是属性名了; } //要导入命名空间 System.Reflection;
using System.Reflection;
class TestField
{
private int i=12;
protected string sabc = "a";
public DateTime dt = DateTime.Now;
static void Main()
{
TestField tf = new TestField();
foreach (FieldInfo fi in tf.GetType().GetFields(BindingFlags.Public|BindingFlags.Instance|BindingFlags.NonPublic))
{
object o = fi.GetValue(tf);
Console.WriteLine("name:{0}==>value:{1}", fi.Name, o.ToString());
}
}
}思归的做法,强
Type ty = typeof(Form);
PropertyInfo[] py = ty.GetProperties();
foreach (PropertyInfo aa in ty)
{
aa.Name;//这就是属性名了;
}
//要导入命名空间 System.Reflection;