【发布时间】:2016-12-31 20:49:06
【问题描述】:
我有一个名为 MyClass 的类,它有很多属性
class MyClass
{
public int Id { get; set; }
public string Name { get; set; }
public string email { get; set; }
public string password { get; set; }
public string city { get; set; }
}
我想在 Console.writeline 中打印属性名称,如
static void Main(string[] args)
{
MyClass m = new MyClass();
var s = m.GetType()
.GetFields();
Console.WriteLine(s);
Console.ReadKey();
}
但它每次都给我
System.Reflection.FieldInfo[]
请告诉我我该怎么做,或者我能不能做到这一点
【问题讨论】:
-
您正在尝试打印出一个对象数组,您希望它做什么?
-
Console.WriteLine(string.Join(", ", s)); -
这将打印出字段的名称,不是属性。
标签: c#