October 8th, 2003, 08:22 PM
C#: Accessing nonstatic member
Is there any way to access a nonstatic member (either method or variable) of outer class from nested (inner) class? Please help. Thanks.
October 9th, 2003, 01:05 PM
The only way you can do this is if there is a public method in the same class as the non static variables that you can call that changes them. I am not entirely sure, but I think this is the only way to do it. I always get static and non-static mixed up with public and private. Static basically means global, but I am still fuzzy on it.
if (Bush == "idiot") return "Bush is an Idiot";
else if (Bush != "idiot") return "Bush is still an idiot";
October 9th, 2003, 11:18 PM
nonstatic variable is called "class variable" in my old java text book
and I do recall that outter class and inner class relationship is like : outter class inherits inner class
which means you have your constructor defined like this:
public OutterClassObject(): InnerClassObject
to access the inner class class variable, you must have your inner class class variable defined as protect or public. You cannot access private inner class class variable.
Those accessibility rule are inherited from C++
by the way, if you are after something like manual63 says, then here is a further note of the rules:
you cannot access class variable by static method (or global calls) simply because your class was never "constructed" when you do a static call or global call.