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 trial

C# C# Objects Object-Oriented Programming Object Initialization

error CS1520: Class, struct, or interface method must have a return type?

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

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

}

I'm getting the error CS1520: Class, struct, or interface method must have a return type

Steven Parker
Steven Parker
229,732 Points

Is the message possibly referring to another module? To facilitate analysis, make a snapshot of your workspace and post the link to it here.

1 Answer

Steven Parker
Steven Parker
229,732 Points

My guess was right, that error was actually for line 8 of "Map.cs".

Constructor methods must have the same name as their class, but here the method name is given as "map" (with lower-case "m") instead of "Map" (with capital "M"). For that reason, it is not recognized as being a constructor; and other methods are required to have a declared return type.