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 Encapsulation and Arrays Ternary If

Nicolas Bastos
Nicolas Bastos
4,209 Points

I am getting an error when compiling the code.

This is the code that I have: namespace TreehouseDefense { class Path {

   private readonly MapLocation[] _path;

   public Path(MapLocaiton[] path)
   {
     _path = path;
   }

    public MapLocation GetLocationAt(int pathStep)
    {
      return (pathStep < _path.Length) ? _path[pathStep] : null;  
    }

}

}

And the error that I get is this: Path.cs(8,20): error CS0246: The type or namespace name 'MapLocation' could not be found. Are you missing an assembly reference?

This is the code from MapLocation.cs: namespace TreehouseDefense {

class MapLocation : Point 
{

    public MapLocation(int x, int y, Map map) : base(x, y) 
    {
          if (!map.OnMap(this))
          {
              throw new OutOfBoundsException(x + "," + y + " is outside the bondaries of the map");
          }
    }
}

}

1 Answer

Steven Parker
Steven Parker
231,236 Points

:point_right: Your build command may be incomplete.

It looks like the MapLocation.cs might not have been included in the build. Did you build using this command?

mcs *.cs -out:TreehouseDefense.exe
Nicolas Bastos
Nicolas Bastos
4,209 Points

Yeah, I keep getting the same error, i dont know what to do.

Steven Parker
Steven Parker
231,236 Points

To allow for a more complete analysis, please make a snapshot of your workspace and provide the link to it.

Steven Parker
Steven Parker
231,236 Points

:point_right: Check the spelling of "MapLocation".

On line 8 of Path.cs you have "MapLocaiton" but it should be "MapLocation".