Click here to Skip to main content
16,020,347 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
"The namespace 'classtester' already contains a definition for 'Control'." I am getting this error message and couldn't figure out how to fix it.

{
    public class Control
    {
        private int top;
        private int left;
        public Control(int top, int left)
        {
            top = top;
            left = left;
        }
        public void DrawControl()
        {
            Console.WriteLine("Drawing Control at {0}, {1}", top, left);
        }
      }
    public class ListBox: Control
{
    private string mListBoxContents;
    public ListBox(int top, int left, string theContent): base(top,left)
{
    mListBoxContents = theContent;
}
    public new void DrawControl()
{
    base.DrawControl();
    Console.WriteLine("Writing string to the ListBox: {0}", mListBoxContents);
}
}
    public class Tester
    {
        public static void Main()
        {
            Control myControl = new Control (5,10);
            myControl.DrawControl();
            ListBox lb = new ListBox (20, 30, "Hello World");
            lb.DrawControl();
        }
    }
}
Posted
Comments
[no name] 3-May-14 22:18pm    
Rename the class that you created named Control to something else.
gggustafson 3-May-14 23:23pm    
+5

1 solution

This is not a complete code sample to identify the problem. You defined the type classtester.Control somewhere else. Remove or rename one of those definitions.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900