Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialThomas Barkel
Courses Plus Student 7,222 Pointserror 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', expecting
class', delegate',
enum', interface',
pa
rtial', or struct'
Map.cs(12,8): error CS1525: Unexpected symbol
Width', expecting class',
delegate', enum',
interface', p
artial', or
struct'
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
231,269 PointsIt 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.