Quote:
Originally Posted by rhyme2ri2
Hi!
I want to use some variables throughout my VC#.net windows based application...........
How can i declare global variables that will work throughout my project...
-Regards
Global variables, especially those being updated from various parts of application, make your code unreadable. General thoughts that should be considered when you want to declare something to be globally available:
- Each variable is bound to some functionality. Thus, it is better to put it to corresponding class as static/instance member, so it will be maintained through methods/properties of that class.
- Static members containing common values that are changed from different places of application can brake encapsulation rule.
Nevertheless it may be useful to separate common constants/settings to a separate internal static class, something like this:
- internal static class Constants
-
{
-
public static int UndefinedID = int.MinValue;
-
-
public bool IsDefined(int id) { return id != UndefinedID; }
-
}
-