title: C# compiler error: "cannot have instance field initializers in structs"
body: <p>I need advice on structures.</p>
  
  <p>I have 2 sections of code. The first section is as below:</p>
  
  <pre><code>namespace Project.GlobalVariables
  {
      class IOCard
      {
          struct InputCard
          {
              public string CardNo;
              public int BaseAddress;
              public int LowerAddress;
              public int UpperAddress;
              public int[] WriteBitNo = new int[16];
              public int[] ReadBitNo = new int[16];
          }
  
          static InputCard[] InputCards = new InputCard[5];
  
          public static string ACardNo = InputCards[1].CardNo;
          public static string BCardNo = InputCards[2].CardNo;
  
      }
  }
  </code></pre>
  
  <p>The second portion is as below:</p>
  
  <pre><code>private void Form1_Load(object sender, EventArgs e)
      {
          IOCard.ACardNo = "Card A";
          IOCard.BCardNo = "Card B";
  
          MessageBox.Show(IOCard.ACardNo);
          MessageBox.Show(IOCard.BCardNo);
      }
  </code></pre>
  
  <p>My plan is to be able to assign and retrieve <code>InputCards</code> component by using <code>IOCard</code> as shown in <code>Form1_Load</code>.</p>
  
  <p>However, when I compile the code, I get the following error.</p>
  
  <blockquote>
    <p>Error 1 'Project.GlobalVariables.IOCard.InputCard.WriteBitNo': cannot have instance field initializers in structs E:\Programming\New platform\StandardPlatform\StandardPlatform\Project\GlobalVariables.cs 16 26 StandardPlatform</p>
  </blockquote>
  
  <p>Can someone tell me how to solve the error?
  Please advise. Thanks.</p>
  
  <p>Here are the classes that I have attempted to create and use, but failed.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  namespace Project.GlobalVariables
  {
      static class IOCard
      {
          public const int TotalInputCard = 10;
          public const int TotalOutputCard = 10;
  
          public  class InputCard
          {
              public string CardNo = "1";
              public int BaseAddress;
              public int LowerAddress;
              public int UpperAddress;
              public int[] WriteBitNo = new int[16];
              public int[] ReadBitNo = new int[16];
          }
  
          public class OutputCard
          {
              public string CardNo;
              public int BaseAddress;
              public int LowerAddress;
              public int UpperAddress;
              public int[] WriteBitNo = new int[16];
              public int[] ReadBitNo = new int[16];
          }
  
          public static InputCard[] InputCards = new InputCard[TotalInputCard];
          public static OutputCard[] OutputCards = new OutputCard[TotalOutputCard];
  
          public static int X100 = InputCards[0].WriteBitNo[0];
          public static int Y100 = OutputCards[0].WriteBitNo[0];
      }
  }
  </code></pre>
  
  <p>I tried to use these in the <code>Form_Load</code>, like so:</p>
  
  <pre><code>private void Form1_Load(object sender, EventArgs e)
  {
      IOCard.X100 = 1;
      IOCard.Y100 = 1;
  } 
  </code></pre>
  
  <p>No matter how much I have tried to search on the net for answers, I have got nowhere.</p>
  
  <p>Please advise. Thanks.</p>