How do I create an array of objects in constructor?
<p>I have two classes:</p>

<p>game</p>

<p>element</p>

<p>I want to be able to define an array of element objects in a game object.  When I try this I get the warning message "..is never assigned to, and will always have its default value null"; in the local variables in the debugger I can see that the array exists, but all entries are null.  The class Element works as I would expect.  If I assign element objects to an array in Main it works, but not when I move the code to the Game constructor.</p>

<p>What am I doing wrong?  I'm new to C# so it could be something very basic. Code below. Many thanks.</p>

<pre><code>class Element
    {
      public Element()
      {
        elements = new List&lt;int&gt;(3);
        elements.Add(1);
        elements.Add(2);
        elements.Add(3);

      }

        List&lt;int&gt; elements;

        public void PrintElement()
      {
          for (int i = 0; i &lt; 3; i++)
          {
              Console.WriteLine("Element {0}: {0}", i + 1, elements[i]);
          }
      }

    }


class Game
    {

            public Game()
            {
                Element1 = new Element();
                Element2 = new Element();
                Element3 = new Element();
                Element[] ThisGame = new Element[3];
                ThisGame[0]= Element1;
                ThisGame[1] = Element2;
                ThisGame[2] = Element3;

            }

            public Element[] ThisGame;
            private Element Element1;
            private Element Element2;
            private Element Element3;

        public void PrintGameElement(int number)
        {
            ThisGame[number].PrintElement();
        }

    }


    class Program
    {
            Game MyGame;
        static void Main(string[] args)
        {

            Game MyGame = new Game();
            MyGame.PrintGameElement(2);


            Console.Read();
        }
    }
</code></pre>
