ASPNET遍历类属性,取值

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace Test
{
class Program
{
static void Main(string[] args)
{
User u = new User();

u.name_ = "ytjjyy";

u.password_ = "XXXBBBCCCC";

Type t = u.GetType();

foreach (PropertyInfo info in t.GetProperties())
{
Console.WriteLine(info.GetValue(u, null));


Console.WriteLine(info.Name);
}

Console.Read();

}
}

public class User
{
public string name_ { get; set; }

public string password_ { get; set; }

public string retrievename()
{
return name_;
}
}
}



posted @ 2012-01-01 22:14  大约  阅读(282)  评论(0编辑  收藏  举报