title: How can I create a reference member variable in C# like in C++
body: <p>Sorry, this is a basic question, which I cannot find an answer to.</p>
  
  <p>I have to write some code in C#, and I need to create a class member variable that is a reference.</p>
  
  <p>In C++ this code would be</p>
  
  <pre><code>public class MyClass
  {
       MyClass(int&amp; m_var): mVar(m_var){}
       int&amp; mVar;
  }
  </code></pre>
  
  <p>However I cannot seem to do this in C#</p>
  
  <p>I can create a constructor with a reference parameter using</p>
  
  <pre><code>MyClass(ref int m_var)
  </code></pre>
  
  <p>But I cannot create a reference member variable using </p>
  
  <pre><code>class MyClass
  {
       MyClass(ref int m_var)
       {
            mVar = m_var;
       }
       ref int mVar;
  }
  </code></pre>
  
  <p>Because the line:</p>
  
  <pre><code>     ref int mVar;
  </code></pre>
  
  <p>Gives me the error: <code>'Invalid Token 'ref' in class, struct, or interface member declaration.</code></p>
  
  <p>Why is this? Why did C# take away the functionality to create reference member variables?</p>