First, check to see if you need a global variable that uses it blatantly instead, ignoring your software architecture.
Suppose he passes the test. Depending on the usage, Globals can be difficult to debug with race conditions and many other “bad things”, it is better to approach them from an angle where you are ready to deal with such bad things. So,
- Wrap all such global variables in one
static class (for manageability). - Have properties instead of fields (= 'variables'). Thus, you have some mechanisms to solve any problems while writing to Globals in the future.
The main plan for this class will be:
public class Globals { private static bool _expired; public static bool Expired { get {
Using other classes (inside the same namespace)
// Read bool areWeAlive = Globals.Expired; // Write // past deadline Globals.Expired = true;
DeepSpace101 Oct 31 '13 at 16:19 2013-10-31 16:19
source share