Globally accessible properties
-
hey all, i'm sure this is a dumb question: but... How do I create / access / modify properties that are available to all classes of my solution? iow, I have a main namespace, and multiple forms that are all separate classes/.dlls. I need to beable to access the properties of the main form throughout the rest of the application, regardless of whether or not the sub classes are instaniated yet. So.. ClassA(mainFrm) calls ClassB(subUsrCrtl1) which does some work then calls ClassC(subUsrCtrl2) which displays extended info from the work done in ClassB. Then ClassA can call ClassD(E,F,G,etc)(subUsrCrtl3(,4,5,6,etc)) who make other information available based on the work done in ClassB. Many of the classes that are available are not used everytime, so they aren't instantiated yet. I need to beable to retrieve data from the work that is completed in ClassB and use that data throughout all available classes. Currently I'm only able to access that data in a class to class relationship where I end up with either old or null values becuase i'm having to instantiate the required class again from the current class...(i.e. ClassA calls ClassD, ClassD needs data from ClassB, so ClassD instantiates new ClassB but that returns null data...) hope this make sense, cause i'm lost.... ehlp.... wait i can't even spell help...
string Beautiful; Beautiful = "ignorant"; label1.Text = "The world is full of " + Beautiful +" people."; Why is common sense such an un-common comodity?
-
hey all, i'm sure this is a dumb question: but... How do I create / access / modify properties that are available to all classes of my solution? iow, I have a main namespace, and multiple forms that are all separate classes/.dlls. I need to beable to access the properties of the main form throughout the rest of the application, regardless of whether or not the sub classes are instaniated yet. So.. ClassA(mainFrm) calls ClassB(subUsrCrtl1) which does some work then calls ClassC(subUsrCtrl2) which displays extended info from the work done in ClassB. Then ClassA can call ClassD(E,F,G,etc)(subUsrCrtl3(,4,5,6,etc)) who make other information available based on the work done in ClassB. Many of the classes that are available are not used everytime, so they aren't instantiated yet. I need to beable to retrieve data from the work that is completed in ClassB and use that data throughout all available classes. Currently I'm only able to access that data in a class to class relationship where I end up with either old or null values becuase i'm having to instantiate the required class again from the current class...(i.e. ClassA calls ClassD, ClassD needs data from ClassB, so ClassD instantiates new ClassB but that returns null data...) hope this make sense, cause i'm lost.... ehlp.... wait i can't even spell help...
string Beautiful; Beautiful = "ignorant"; label1.Text = "The world is full of " + Beautiful +" people."; Why is common sense such an un-common comodity?
If you want values to be used across different instances it is better to make those properties as
static
members of the class and access them from the class scope. A better approach would be to take out the information you want to make available across the application and put them into one class. Make a static instance of that class to use across the other classes.--------------------------------------------------