- using System;
- //Declare GLOBALS class in global namespace or wherever you want
- public static class GLOBALS
- {
- public const int KEY = 5000;
- public static string STATUS = "NULL";
- }
- namespace Test
- {
- class Program
- {
- public static void MyMethod()
- {
- //Do something
- GLOBALS.STATUS = "MYMETHOD";
- }
- static void Main(string[] args)
- {
- Console.WriteLine("KEY:{0,10:d}", GLOBALS.KEY);
- Console.WriteLine("STATUS: {0}", GLOBALS.STATUS);
- Console.WriteLine();
- MyMethod();
- Console.WriteLine("KEY:{0,10:d}", GLOBALS.KEY);
- Console.WriteLine("STATUS: {0}", GLOBALS.STATUS);
- }
- }
- }
C# GLOBALS
Global values are useful to store constant values of your program or transfer values between different scopes. They can be accessed anywhere. Unfortunately there is not any predefined struct in .NET .
Globals is defined using static class.