title: Variable length arrays in C#
body: <p>I have a class which defines few global variables as below:</p>
  
  <pre><code>namespace Algo
  {
      public static class AlgorithmParameters
      {
          public int pop_size = 100;
  
      }
  }
  </code></pre>
  
  <p>In my another csharp file, which also contains the main(), and in the main() I am declaring an array of type structure and the array size as pop_size but I am getting some error on <code>"chromo_typ Population[AlgorithmParameters.pop_size];"</code>. Please find the code below. Am I using a incorrect syntax for array declaration of variable length size??</p>
  
  <pre><code>namespace Algo
  {
      class Program
      {
          struct chromo_typ
          {
              string   bits;  
              float    fitness;
  
              chromo_typ() {
                  bits = "";
                  fitness = 0.0f;
              }
  
              chromo_typ(string bts, float ftns)
              {
                  bits = bts;
                  fitness = ftns;
              }
          };
  
          static void Main(string[] args)
          {
  
              while (true)
              {
                  chromo_typ Population[AlgorithmParameters.pop_size];
              }
          }
      }
  }
  </code></pre>
  
  <p>Error is:</p>
  
  <pre><code>Bad array declarator: To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type.
  
  Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)
  </code></pre>
  
  <p>Please help.</p>