title: C# Equivalent for VB 'module'
body: <p>In Visual Basic, you can use a module as a place to store 'loose' code which can be methods and variables that are accessible from elsewhere in the application without having to first initialize something, and the variable states can be set or changed and will continue to keep that value throughout.</p>
  
  <p>The closest I have found, is static methods in C# as part of a public class, however this has the drawback of variables which are not globally accessible, or internally settable/gettable if the variables are made static.</p>
  
  <p>Take for example the following simple code in VB stored in a blank module.</p>
  
  <pre><code>Private iCount as Integer = 0
  
  Public Sub Increment()
    iCount = iCount + 1
  End Sub
  
  Public CheckModulus() As Boolean
    If iCount % 6 == 0 Then
      Return True
    Else
      Return False
    End If
  End Sub
  </code></pre>
  
  <p>Now, you have a class, and from that class, you can then call <code>CheckModulus()</code> as such</p>
  
  <pre><code>Public Class Fruits
  
     Public Static Function ExactBunches() As String
        If CheckModulus() Then
           Return "You have an exact amount of bunches"
        Else
           Return "You need more fruits to make a bunch"
        End If
     End Function
  
  End Class
  </code></pre>
  
  <p>Now I realize with some hack and slash, that you could move iCount to 'settings', and reset it on application launch, etc, but please bear in mind this is a very simple example to illustrate the convenience of being able to have a set of global code.  Where I have found this most useful in the past is when creating UserControls or custom classes.  In addition, the intent is not to make everything globally accessable, but to have certain methods and variables globally accessable while others remain ONLY accessible from within the module.  For example, while <code>CheckModulus()</code> and <code>Increment()</code> (global methods) both have access to modify and obtain the <code>iCount</code> value, <code>iCount</code> is not accessible globally, as would the way be with private defined methods in the module.</p>
  
  <p>So the big pickle is this :</p>
  
  <blockquote>
    <p>What is the functionally equivalent code type in C# to VB &amp; VB.NET's
    <code>module</code> ?</p>
  </blockquote>
  
  <p>Due to the complex nature of this simple question, I feel I should impose a boolean for a 'just in case there is no answer' answer as follows.</p>
  
  <blockquote>
    <p>If, there is nothing functionally equivalent, then what sort of clever
    hack or workaround (aside from using settings, or external storage
    like the registry, database, files, etc), to make this happen or
    something VERY very close ?</p>
  </blockquote>