1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Rep Power

    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.
  2. #2
  3. Sk8er Punk!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Minneapolis, MN
    Rep Power
    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";

  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Brisbane, Australia
    Rep Power
    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
    //construction code

    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.

IMN logo majestic logo threadwatch logo seochat tools logo