Alternative to global variables on C#
<p>I'm currently learning C# having been most familiar with Ruby previously, and I was writing some code which required a bool variable to be accessed from multiple places, to check and/or set the state. In Ruby this would be a piece of cake, just declare $my_global_variable = false (or whatever). Having looked this up I was successfully able to replicate this in C# by declaring the following:</p>

<pre><code>public class GlobalVariables  
{  
    public static bool exampleGlobalVariable;  
}  
</code></pre>

<p>And then accessing GlobalVariables.exampleGlobalVariable whenever I need to. However everything I read about global variables in C# suggests that they're considered problematic and if you implement them you're a terrible person.</p>

<p>So my question is, what alternatives are there? Passing variables back and forth is messy to my eye and sometimes it's not even possible - if a method is already passing back a variable, for example.</p>

<p>Is there another way of achieving this functionality that's neat and idiomatic for C#?</p>