如何获取值为null的对象的父类?
例如...
ClassA包含int? i在创建类时未设置为任何值的包含.
然后在代码中的其他地方我想i作为参数传递给某个函数.使用i作为唯一的信息,我希望能够找出ClassA"拥有" i.
原因是因为ClassA还包含一些其他对象,我想从上一段中提到的相同函数中调用这个其他对象的值.
也可能是:
public class A
{
public class B
{
public int? i;
public int? j;
}
B classBInstance = new B();
public string s;
}
{
...
A someClassAInstance = new A();
...
doSomething(someClassAInstance.classBInstance.i);
...
}
public static bool doSomething(object theObject)
{
string s = /* SOMETHING on theObject to get to "s" from Class A */;
int someValue = (int)theObject; …Run Code Online (Sandbox Code Playgroud)