title: Passing a static variable by reference in a class constructor
body: <pre><code>public class Gameplay {
     public static int count = 0;
  
     AClass aClass = new AClass(ref count);
  }
  
  public class AClass {
     public int count { get; set; }
  
     public AClass(ref int c) {
         this.count = c;
     }
  
     public void printCount() {
         Console.WriteLine(this.count.ToString());
     }
  }
  </code></pre>
  
  <p>I have two classes like the ones above. Suppose the count variable of Gameplay increases in another class that does <em>Gameplay.count++</em>. I want AClass.count to always be equal to Gameplay.count.</p>
  
  <p>Now, surely I could just use Gameplay.count inside AClass but if I have different counts to pass in different instances of AClass it's better to have the reference to the count you want to access. The above example always writes 0 even if Gameplay count has increased.</p>