title: How to set null a specific element of an array in C#?
body: <p>I´m doing a console application that removes an element of an array if a passed number by parameter appears more than one time as element of the array.</p>
  
  <p>I ´ve done the main algorithm but I can´t set null the element. Here is my code:</p>
  
  <pre><code>static int[] RemoveElement(ref int[] array, int num)
  {
      int i;
      for (i = 0; i &lt; array.Length; i++)
      {
          if (array[i] == num)
          {
              array[i] = 1; //This is a temporal solution.
          }
      }
  
      return array;
  }
  </code></pre>
  
  <p>Here is the Main:</p>
  
  <pre><code>static void Main(string[] args)
  {
      int[] a = {10, 2, 2, 3, 4};
  
      Console.WriteLine("Write a number:");
      int b = int.Parse(Console.ReadLine());
  
      int[] arrayInts = RemoveElement(ref a, b);
  
      foreach (var variable in arrayInts)
      {
          Console.WriteLine(variable);
      }
  
      Console.ReadKey();
  }
  </code></pre>
  
  <p>Thanks in advance! :-)</p>