title: Best practices to using global variables in C#
body: <p><a href="http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/071dc2fb-76c3-4484-8418-6b37664995f7/" rel="nofollow noreferrer">Someone once said</a>:</p>
  
  <blockquote>
    <p><em>a "global variable" is really a variable you create to simply "hold some information" because your object model is weak, and you haven't found a "true purpose" for the variable to exist.  Global variables are almost always a sign of a larger architectural deformity.</em></p>
  </blockquote>
  
  <p><a href="http://www.c2.com/cgi/wiki?GlobalVariablesAreBad" rel="nofollow noreferrer">That might be true</a>. But I don't know of any good example of any big and good program made without global variables, and certainly not used as little as above suggested. <a href="https://stackoverflow.com/questions/357187/when-are-global-variables-acceptable"><strong>Scope</strong> is the actual key</a>. You can say <a href="https://stackoverflow.com/a/1263220/274502">in a program with only one class</a> that its parameters are <a href="https://stackoverflow.com/questions/895595/how-do-i-persist-data-without-global-variables">not global vars</a>. But they are.</p>
  
  <p>Anyway...</p>
  
  <p>I'm still grasping the concept of <strong><a href="http://en.wikipedia.org/wiki/Singleton_pattern" rel="nofollow noreferrer">singleton</a></strong> and, as far as I can tell, they <a href="https://stackoverflow.com/questions/3136008/is-this-singleton-implementation-correct-and-thread-safe">actually</a> make no sense in C#. Also I get the feeling that when having a global state can't be avoided we still should avoid simply using a public class full of <strong><a href="https://stackoverflow.com/a/1163016/274502">static properties</a></strong>:</p>
  
  <p>So, if not singletons nor a public class, what should we do to have global vars in C#?</p>
  
  <p>And when are we supposed to use them? Assuming they most likely can't be avoided. Ever.</p>
  
  <p>And why should we avoid using a <a href="https://stackoverflow.com/a/8734537/274502">static class</a> or <code>static</code> in general? If that's indeed the case for C#.</p>
  
  <p>In one sentence: <strong>What are the best practices on using global variables in Csharp</strong>?</p>