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 Object-Oriented Programming Object Initialization

I'am getting an extra warning

The variable Width and height is not assigned a value and it's default value is 0; My code is similar to the code in video i have compared it?What should i do now?

Steven Parker
Steven Parker
231,184 Points

If you'd like help analyzing your code please post it here, or better yet, make a snapshot of your workspace and post the link to that.

luke hammer
luke hammer
25,513 Points

Please post your code.

I ran into this as well, but I was able to work it out. Hopefully, it will resolve the issue for others that run into this as well.

Code when I received the error:

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

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

Error Game.cs(9,15): warning CS0219: The variable area' is assigned but its value is never used Map.cs(10,7): warning CS1717: Assignment made to same variable; did you mean to assign somethin g else? Map.cs(11,7): warning CS1717: Assignment made to same variable; did you mean to assign somethin g else? Map.cs(5,25): warning CS0649: FieldTreehouseDefense.Map.Width' is never assigned to, and will always have its default value 0' Map.cs(6,25): warning CS0649: FieldTreehouseDefense.Map.Height' is never assigned to, and wil l always have its default value `0'
Compilation succeeded - 5 warning(s)

Code to resolve the extra errors:

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

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