日期:2014-05-17 浏览次数:20536 次
class Program
{
static void Main(string[] args)
{
List<object> olist = new List<object>();
olist.Add(new { Name = "Hauk", Age = 22 });
olist.Add(new { Name = "Emily", Age = 22 });
var obj = ChangeType(olist[0], new { Name = "", Age = 0 });
Console.WriteLine(obj.Name);
Console.WriteLine(olist[0].GetType().GetProperty("Name").GetValue(olist[0]).ToString());
}
static T ChangeType<T>(object obj, T t)
{
return (T)obj;
}
}