2,854 questions
Hello @兰树豪,
Can you try below code:
Type myType = typeof(MyClass);
// Get all static members of MyClass
FieldInfo[] staticFields = myType.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
// Display the names of all static members
Dictionary<string,string> map = new Dictionary<string,string>();
foreach (FieldInfo field in staticFields)
{
object value = field.GetValue(null);
map.Add(field.Name, value.ToString());
}
foreach(string key in map.Keys) {
Console.WriteLine("{0}={1}",key, map[key].ToString());
}