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 Methods Return Values

compilation succeeded - 8 warning(s)

My code is coming up with warnings about me not assigning anything however I feel like I have the same code as the lecturer but mine isn't returning. Can someone help!

Error messages: " treehouse:~/workspace$ mcs -out:Treehouse.Defense.exe *.cs && mono TreehouseDefense.exe
Map.cs(10,7): warning CS1717: Assignment made to same variable; did you mean to assign something else?
Map.cs(11,7): warning CS1717: Assignment made to same variable; did you mean to assign something else?
Point.cs(10,9): warning CS1717: Assignment made to same variable; did you mean to assign something else?
Point.cs(11,9): warning CS1717: Assignment made to same variable; did you mean to assign something else?
Map.cs(5,25): warning CS0649: Field TreehouseDefense.Map.Width' is never assigned to, and will always have its default value0'
Map.cs(6,25): warning CS0649: Field TreehouseDefense.Map.Height' is never assigned to, and will always have its default value0'
Point.cs(5,23): warning CS0649: Field TreehouseDefense.Point.X' is never assigned to, and will always have its default value0'
Point.cs(6,23): warning CS0649: Field TreehouseDefense.Point.Y' is never assigned to, and will always have its default value0'
Compilation succeeded - 8 warning(s) " URL to my work: https://w.trhou.se/9xa4n5znko

Thanks

1 Answer

Steven Parker
Steven Parker
231,248 Points

The compiler noticed that you were assigning the variable to itself in several cases, which isn't an outright error but doesn't make sense. In all cases this is happening in the class constructors, where what should be happening is the values passed in as argument assigned to the class fields. Here's the lines from the "Map" class as an example:

      width = width;
      height = height;

Notice that the same name appears on both sides of the assignments. But the field names all start with capital letters, so the name on the left is not correct. The "Point" class has a similar issue. Fix the capitalization of the names and you should be in good shape.

Yep that worked! Didn't notice my caps :O.. Sometimes it's the silly mistakes like that.

Thanks Steven :)