title: how to initialize array to -1 fast?
body: <p>I understand that I should not optimize every single point of my program, let's just assume that I have to optimize array initialization.</p>
  
  <p>So I wrote program that compares <code>for loop</code> versus <code>Array.Clear</code></p>
  
  <pre><code>using System;
  using System.Diagnostics;
  
  namespace TestArraysClear
  {
      class Program
      {
          static void Main(string[] args)
          {
              int[] a = new int[100000];
              Stopwatch sw = Stopwatch.StartNew();
              for (int i = 0; i &lt; 10; i++)
              {
                  sw.Reset(); 
                  sw.Start();
                  for (int j = 0; j &lt; a.Length; j++)
                  {
                      a[j] = 0;
                  }
                  sw.Stop();
                  Console.WriteLine("for " + sw.ElapsedTicks);
                  sw.Reset();
                  sw.Start();
                  Array.Clear(a, 0, a.Length);
                  sw.Stop();
                  Console.WriteLine("Array.Clear " + sw.ElapsedTicks);
              }
          }
      }
  }
  </code></pre>
  
  <p>Output on my machine:</p>
  
  <pre><code>for 1166
  Array.Clear 80
  for 1136
  Array.Clear 91
  for 1350
  Array.Clear 71
  for 1028
  Array.Clear 72
  for 962
  Array.Clear 54
  for 1185
  Array.Clear 46
  for 962
  Array.Clear 55
  for 1091
  Array.Clear 55
  for 988
  Array.Clear 54
  for 1046
  Array.Clear 55
  </code></pre>
  
  <p>So <code>Array.Clear</code> is about 20 times faster than <code>for loop</code>. But <code>Array.Clear</code> initializes to <code>0</code>. Can I initialize array to <code>-1</code> with the same perfomance somehow?</p>
  
  <p><strong>upd:</strong> I'm not looking for some "extreme unsafe" code. I'm looking for something as easy as <code>Array.Clear</code>. I just wonder that .NET offers fast 0 initialization, but .NET doesn't offer initialization to other values. So why .NET like "0" much more than "-1"?</p>
  
  <p><strong>upd</strong> I want to reset existent array. So i'm looking for analog of <code>Array.Clear</code> which will reset array to <code>-1</code>, not <code>0</code></p>