-2
如何使用SubClass1
類型處理SuperClass1
中的所有字段?如何從嵌套類訪問包含類的字段
這是我到目前爲止有:
namespace ConsoleApplication9
{
class Program
{
static void Main(string[] args)
{
SuperClass1.SubClass1 class1 = new SuperClass1.SubClass1();
PrintAllFields(class1);
}
public static void PrintAllFields(object obj)
{
var SuperClassType = obj.GetType();
// How do I get the fields 'param1', 'param2', 'param3' from here?
SuperClassType.GetFields();
}
}
public class SuperClass1
{
public int param1;
public int param2;
public int param3;
public class SubClass1
{
public int paramTest;
}
}
}