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 Inheritance Throwing Exceptions

Error

I get this error when compiling and running my code; and can't figure out what it means:

MapLocation.cs(3,25): error CS0246: The type or namespace name Point' could not be found. Are you missingTreehouseDefense' using directive?
MapLocation.cs(5,42): error CS0246: The type or namespace name Map' could not be found. Are y ou missingTreehouseDefense' using directive?
Compilation failed: 2 error(s), 0 warnings

This is my Map.cs code:

using System;

namespace TreehouseDefense { class Map { public readonly int Width; public readonly int Height;

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

    public bool OnMap(Point point)
    {
       return point.X >= 0 && point.X < Width && 
              point.Y >= 0 && point.Y < Height;
    }
}  

}

I found a typo in one of my other files and it fixed these errors. Unfortunately, I have new errors now. I will post a new question for those.

Steven Parker
Steven Parker
231,269 Points

You could delete this question if you don't need it answered, or you could edit this question to reflect your current issues.

And when posting code, please use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:

UPDATE :point_right: Or watch this video on code formatting.

1 Answer

steven simpson
steven simpson
11,644 Points

When you made your point class and the other class did you make them public?

This can be done like this when u make the point class

public class point { some variables here public constructor here methods and what not here codes goes here for the class does }

or you need to add the class at the top of the screen by using the using point;

hope this help