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 Encapsulation with Properties Computed Properties

Preview points to, "Square.cs(11,24): error CS0103: The name `Math' does not exist in the current context.....

Not sure what am I doing incorrectly

Square.cs
namespace Treehouse.CodeChallenges
{
    class Square : Polygon
    {    
        public double SideLength { get; private set; }

        public double Area 
        {
            get
            {
                return Math.Sqrt(SideLength);
            }
        } 

        public Square(double sideLength) : base(4)
        {
            SideLength = sideLength * sideLength ;
        }    

    }
}
Polygon.cs
namespace Treehouse.CodeChallenges
{
    public class Polygon
    {
        public int NumSides { get; private set; }

        public Polygon(int numSides)
        {
            NumSides = numSides;
        }
    }
}

1 Answer

Calin Bogdan
Calin Bogdan
14,920 Points

Hi!

Math is a class belonging to the System namespace.

In order to be able to use it, you have to add a line at the top of your file stating that you want to use this namespace, like so:

using System;

Good luck!

Thank you Calin Bogdan, appreciate you time and help.