title: C# Overwrite string and string[] in another Function
body: <p>I overwrite the variables 'arr[1]' and 'test' in setValues() function.</p>
  
  <p>arr[1] is changed to 'BBB'</p>
  
  <p>but test doesn't change to '222'</p>
  
  <blockquote>
    <p>Output: BBB111</p>
  </blockquote>
  
  <p>but it should be BBB222</p>
  
  <p>Why string test doesn't get updated?</p>
  
  <pre><code>public class Program
      {
          static void Main(string[] args)
          {
              string[] arr = new string[10];
  
              arr[1] = "AAA";
              string test = "111";
  
              setValues(arr, test);
  
              int exit = -1;
              while (exit &lt; 0)
              {
  
                  for (int i = 0; i &lt; arr.Length; i++)
                  {
                      if (!String.IsNullOrEmpty(arr[i]))
                      {
                          Console.WriteLine(arr[i] + test);
                      }
                  }
              }
          }
  
          private static void setValues(string[] arr, string test)
          {
              arr[1] = "BBB";
              test = "222";
          }
      }
  </code></pre>