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 trialYoel Dovid Cohen
13,405 PointsPLEASE HELP! error CS0246
When I try to compile Game.cs this error comes up:
Game.cs(7,11): error CS0246: The type or namespace name `Map' could not be found. Are you missing an assembly reference?
Game.cs(9,22): error CS0841: A local variable `map' cannot be used before it is declared
Compilation failed: 2 error(s), 0 warnings
And when I try to compile Map.cs this error comes up:
Map.cs(14,25): error CS0246: The type or namespace name `Point' could not be found. Are you missing an assembly reference?
Here is my code for Game.cs:
namespace TreehouseDefense
{
class Game
{
public static void Main()
{
Map map = new Map(8, 5);
int area = map.Width * map.Height;
}
}
}
And here is my 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;
}
public bool OnMap(Point point)
{
return point.X >= 0 && point.X < Width
&& point.Y >= 0 && point.Y < Height;
}
}
}
I will be very grateful if someone will tell me what I missed. Thank you
James Meyer
8,985 PointsSo, I'm not too familiar with C#, but I feel as though you are missing the "using" keyword somewhere. Maybe something along the lines of "using Map" or "using TreehouseDefense". I figured maybe this might help face you in the right direction. Like I said, I don't really have experience with C#, but I did a little googling and hopefully this helps!
Steven Parker
231,269 PointsJames, "using" isn't needed here since all modules are part of the same namespace. The "using" directive gives you access to things in a different namespace.
3 Answers
Steven Parker
231,269 PointsAt first glance, the code looks OK, so I suspect the issue might be in the way the way the program is being compiled. Since the modules depend on each other, it's important to compile them all together. Compiling them individually is likely to cause the errors your are seeing.
A typical build command might look like this:
mcs -out:treehousedefense.exe *.cs
Yoel Dovid Cohen
13,405 PointsThank you. It worked
Johan Kjellin
2,740 PointsI got the same error, however I found that I write TreehouseDefence instead of TreehouseDefense
Steven Parker
231,269 PointsSpelling isn't important as long as it is consistent.
Holly Ziobro
3,072 PointsHolly Ziobro
3,072 PointsHi,
Do you have code in another class relating to Point?