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_;
}
}
}



原文地址:https://www.cnblogs.com/ytjjyy/p/2309653.html