title: Initialize a byte array to a certain value, other than the default null?
body: <p>I'm busy rewriting an old project that was done in C++, to C#. </p>
  
  <p>My task is to rewrite the program so that it functions as close to the original as possible.</p>
  
  <p>During a bunch of file-handling the previous developer who wrote this program creates a structure containing a ton of fields that correspond to the set format that a file has to be written in, so all that work is already done for me. </p>
  
  <p>These fields are all byte arrays. What the C++ code then does is use <code>memset</code> to set this entire structure to all spaces characters (<code>0x20</code>). One line of code. Easy.</p>
  
  <p>This is very important as the utility that this file eventually goes to is expecting the file in this format. What I've had to do is change this struct to a class in C#, but I cannot find a way to easily initialize each of these byte arrays to all space characters.</p>
  
  <p>What I've ended up having to do is this in the class constructor:</p>
  
  <pre><code>//Initialize all of the variables to spaces.
  int index = 0;
  foreach (byte b in UserCode)
  {
      UserCode[index] = 0x20;
      index++;
  }
  </code></pre>
  
  <p>This works fine, but I'm sure there must be a simpler way to do this. When the array is set to <code>UserCode = new byte[6]</code> in the constructor the byte array gets automatically initialized to the default null values. Is there no way that I can make it become all spaces upon declaration, so that when I call my class' constructor that it is initialized straight away like this? Or some <code>memset</code>-like function?</p>