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#

Getting a runtime error on my Level class constructor

Hi!

I'm getting the following error:

Level.cs(9,10): error CS1520: Class, struct, or interface method must have a return type

Up to that point, my code looks like this: (Line 9 is the "public Level(Invader[] invaders)" line)

namespace TreehouseDefense
{
    class level
    {
        private readonly Invader[] _invaders;

        public Tower[] Towers { get; set; }

        public Level(Invader[] invaders)
        {
            _invaders = invaders;
        }

This looks identical to the code in the video. What am I missing?

Thanks!

1 Answer

Steven Parker
Steven Parker
231,072 Points

Since the class is named "level" (with lower-case "l"), the method "Level" (capital "L") is not recognized as a constructor; and since normal methods must have a return type this message is generated.

Always be sure the class name and constructor name(s) are exactly the same, including case.

That was it! Thanks!