title: C# Passing arguments by default is ByRef instead of ByVal
body: <p>I know the default is ByVal in C#. I used same variable names in many places and then I noticed passed values change and come back. I think I knew scope mechanism of C# wrong. Here public <strong>license</strong> overrides the local <strong>license</strong> values. I know I can easily rename the variable names in conflict but I would like to learn the facts about scope.</p>
  
  <pre><code>  public static class LicenseWorks
    {
       public static void InsertLicense(License license)
       {
          license.registered = true;
          UpdateLicense(license);
       }
    }
  
    public partial class formMain : Form
    {
       License license;
  
       private void btnPay_Click(object sender, EventArgs e)
       {
            license.registered = false;
            LicenseWorks.InsertLicense(license);
  
            bool registered = license.registered; //Returns true!
        }
    }    
  </code></pre>
  
  <p><strong>Update:</strong> I've added below as solution:</p>
  
  <pre><code>    public static void InsertLicense(License license)
      {
  
          license = license.Clone();
          ...
       }
  </code></pre>