I have got a class which contains more then 150 fields. i need the name of fields (not value) in an array.
because its very hard and not a good approach to write 150
This work for me perfectly ExampleClass is class You need list all fields
public void GetClassFields(Type t)
{
List fieldNames = new List(t.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Select(x => x.Name));
foreach (string name in fieldNames)
{
Console.WriteLine(name);
}
}
//Usage
GetClassFields(typeof(ExampleClass));