C# C# Objects Object-Oriented Programming Object Initialization

Thomas Barkel
PRO
Thomas Barkel
Pro Student 7,222 Points

error CS1525: Unexpected symbol. Please help

I'm getting a compiler error despite copying the video's code. Please assist! The error is: "Map.cs(10,13): error CS1525: Unexpected symbol Map', expectingclass', delegate',enum', interface',pa rtial', or struct' Map.cs(12,8): error CS1525: Unexpected symbolWidth', expecting class',delegate', enum',interface', p artial', orstruct'
Map.cs(14,7): error CS1514: Unexpected symbol }', expecting.' or `{'
Compilation failed: 3 error(s), 0 warnings "

HERE'S THE CODE FOR MAP.CS:

namespace TreeHouseDefense
{

    class Map 
    {
      public readonly int Width;
      public readonly int Height;
    }

      public Map(int width, int height)
      {
        Width = width;
        Height = height;
      }

}

HERE'S THE CODE FOR GAME.CS:

namespace TreeHouseDefense
{
    class Game
    {
        public static void Main()
        {
            Map map = new Map(8, 5);

            int area = map.Width * map.Height;
        }
    }
}

1 Answer

Steven Parker
Steven Parker
174,115 Points

It looks like the constructor function for "Map" is outside of the class.

The quick fix would be to move the first closing brace ("}") down to right after the 2nd one.

For future issues, an easy and effective way to share both the code and the project environment is to make a snapshot of your workspace and post the link to it here.