c# - "The namespace 'console' already contains a definition for 'Circle'" -


i'm working on code school project, have class defining circle , method draws, code far returns "the namespace 'console' contains definition 'circle' here code:

using system; using system.collections.generic; using system.linq; using system.text;  namespace console {     class program     {          static void main(string[] args)         {              console.write("what circle’s radius: ");             double radius = convert.todouble(console.readline());             circle ans = new circle(radius);               console.writeline("the area of circle " + ans.getarea);             console.writeline("the diameter of circle " + ans.getdiameter);             console.writeline("the circumference of circle " + ans.getcircumference);              console.write("enter character quit program. ");             double stop = console.read();          }     } } 

that's method , class:

using system; using system.collections.generic; using system.linq; using system.text;  namespace console {     class circle     {   public double radius;             public const double pi = 3.14159;             public circle(double r)             {             radius = r;         }         public circle()         {             radius = 0.0;         }          public double getdiameter         {                         {                 return radius * 2;             }          }           public double getarea         {                         {                 return pi * radius * radius;             }          }         public double getcircumference         {                         {                 return 2 * pi * radius;             }          }         // property radius          public double radius         {                         {                 return radius;             }              set             {                 // ensure non-negative radius value                  if (value >= 0)                     radius = value;             }         }     } } 

one final question this, have working code, set , supposed not allow negative input. however, when run, negative input still returns results, missing causing negative values still calculated?

the error quite specific. you've declared 2 classes same name circle in same namespace. can't that. compiler needs able distinguish between 2 classes, how can if have same name?

i recommend changing name of class contains main entry point more appropriate, such program.

also, practice should stick accepted naming conventions , name namespace console, rather console.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -