Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

C# C# Objects Object-Oriented Programming Fields

Ruslan T
Ruslan T
1,706 Points

tower, map is assigned but it's value is never used

Game.cs(7,17): warning CS0219: The variable `tower' is assigned but its value is never used

Game.cs(13,15): warning CS0219: The variable `area' is assigned but its value is never used

I get this error when I try to compile the program, can anyone help?

namespace TreehouseDefence

{

class Game

{
    public static void Main()

    {

      Tower tower = new Tower();

      Map map = new Map();

      map.width = 8;

      map.height = 5;

      int area = map.width * map.height;

    }

}

}

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! To be clear, you are not getting errors, you are are getting warnings. There's a difference here. And the warning is saying exactly what it means. You've declared a variable named tower but haven't used it. If you take a look at 3:29 of the video linked to this challenge, you'll see that the line with tower is not present. Now, this might happen in a later video, but as of right now, it is not used.

Again, this is just a warning. It's just letting you know that you've declared a variable you haven't actually used. But that doesn't mean you won't use it later :smiley:

Hope this helps! :sparkles:

Ahmed M
Ahmed M
4,008 Points

that is not a error you just didn't use the value