Sign in to follow this  
NotSlyPee

"member names cannot be the same as their enclosing type" Error

Recommended Posts

Hi, i've got "member names cannot be the same as their enclosing type" while compiling a C# code that i wrote. More details about the error:
Error	1 'Form1': member names cannot be the same as their enclosing type Line 91 Column 3
And that's the whole code: Edit: Please use source tags when you want to include code than spans over more than 10-15 lines - Emmanuel Deloget.
public partial class Form1 : Form
    {
        Random randomNo = new Random();
        int no1;
        int no2;
        string problemType = "+";

        public Form1()
        {
            InitializeComponent();
        }

        private void StartGame_C1ick(object sender, EventArgs e)
        {
            StartGame.Visible = false;
            CheckAnswer.Visible = true;
            Question.Visible = true;
            Answer.Visible = true;
            NextQuestion.Visible = true;
            Feedback.Text = "";
            Feedback.Visible = true;
            Gen_Question();
        }

        private void Gen_Question()
        {
            no1 = randomNo.Next(100);
            no2 = randomNo.Next(100);

            if (radioButton1.Checked)
            {
                problemType = "+";
            }
            else if (radioButton2.Checked)
            {
                problemType = "-";
            }

            else if (radioButton3.Checked)
            {
                problemType = "*";
            }

            Question.Text = no1 + problemType + no2 + "=";
        }
        private void CheckAnswer_Click(object sender, EventArgs e)
        {
            int result = 0;
            if (problemType == "+")
            {
                result = no1 + no2;
            }
            else if (problemType == "-")
            {
                result = no1 - no2;
            }
            else if (problemType == "*")
            {
                result = no1 * no2;
            }

            if (Answer.Text == result.ToString())
            {
                Feedback.Text = "Correct";
            }
            else
            {
                Feedback.Text = "Incorrect";
            }

        }

        private void NextQuestion_Click(object sender, EventArgs e)
        {
            Gen_Question();

            Answer.Text = "";
            Feedback.Text = "";
        }

        public partial class Form1 : Form
        {
            Random randomNo = new Random();
            int no1;
            int no2;
            string problemType = "+";

            public Form1()
            {
                InitializeComponent();
            }

            private void StartGame_Click(object sender, EventArgs e)
            {
                StartGame.Visible = false;
                CheckAnswer.Visible = true;
                Question.Visible = true;
                Answer.Visible = true;
                NextQuestion.Visible = true;
                Feedback.Text = "";
                Feedback.Visible = true;
                Gen_Question();
            }

            private void Gen_Question()
            {
                no1 = randomNo.Next(100);
                no2 = randomNo.Next(100);

                if (radioButton1.Checked)
                {
                    problemType = "+";
                }
                else if (radioButton2.Checked)
                {
                    problemType = "-";
                }
                else if (radioButton3.Checked)
                {
                    problemType = "*";
                }

                Question.Text = no1 + problemType + no2 + "=";
            }

            private void CheckAnswer_Cl1ck(object sender, EventArgs e)
            {
                int result = 0;
                if (problemType == "+")
                {
                    result = no1 + no2;
                }
                else if (problemType == "-")
                {
                    result = no1 - no2;
                }
                else if (problemType == "*")
                {
                    result = no1 * no2;
                }

                if (Answer.Text == result.ToString())
                {
                    Feedback.Text = "Correct";
                }
                else
                {
                    Feedback.Text = "Incorrect";
                }
            }

            private void NextQuestion_C1ick(object sender, EventArgs e)
            {
                Gen_Question();
                Answer.Text = "";
                Feedback.Text = "";
            }
        }
    }
}
[Edited by - Emmanuel Deloget on March 12, 2007 9:54:54 AM]

Share this post


Link to post
Share on other sites
Can't you see it? About halfway down your code you have a copy of your class.

    public partial class Form1 : Form
{
Random randomNo = new Random();
int no1;
int no2;
string problemType = "+";

public Form1()
{
InitializeComponent();
}

private void StartGame_C1ick(object sender, EventArgs e)
{
StartGame.Visible = false;
CheckAnswer.Visible = true;
Question.Visible = true;
Answer.Visible = true;
NextQuestion.Visible = true;
Feedback.Text = "";
Feedback.Visible = true;
Gen_Question();
}

private void Gen_Question()
{
no1 = randomNo.Next(100);
no2 = randomNo.Next(100);

if (radioButton1.Checked)
{
problemType = "+";
}
else if (radioButton2.Checked)
{
problemType = "-";
}

else if (radioButton3.Checked)
{
problemType = "*";
}

Question.Text = no1 + problemType + no2 + "=";
}
private void CheckAnswer_Click(object sender, EventArgs e)
{
int result = 0;
if (problemType == "+")
{
result = no1 + no2;
}
else if (problemType == "-")
{
result = no1 - no2;
}
else if (problemType == "*")
{
result = no1 * no2;
}

if (Answer.Text == result.ToString())
{
Feedback.Text = "Correct";
}
else
{
Feedback.Text = "Incorrect";
}

}

private void NextQuestion_Click(object sender, EventArgs e)
{
Gen_Question();

Answer.Text = "";
Feedback.Text = "";
}

// Remove duplicate here.
}




jfl.

Share this post


Link to post
Share on other sites
Oh sorry, that was stupid. But now i get another error while compiling: 'MathGame.Form1' does not contain a definition for 'StartGame_Click' line 163 column 66. And here's the computer generated code (in form1.designer.cs) where the error is found:

// 
// StartGame
//
this.StartGame.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.Fontstyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(186)));
this.StartGame.ForeColor = System.Drawing.Color.DarkBlue;
this.StartGame.Location = new System.Drawing.Point(185, 347);
this.StartGame.Name = "StartGame";
this.StartGame.Size = new System.Drawing.Size(104, 27);
this.StartGame.TabIndex = 7;
this.StartGame.Text = "Start Game";
this.StartGame.UseVisualstyleBackColor = true;
this.StartGame.Click += new System.EventHandler(this.StartGame_Click);
//
// Form1
//

Share this post


Link to post
Share on other sites
Well, do note that in the original code you posted, StartGame_Click() does not exist, you have StartGame_C1ick() (a one instead of an 'l').


jfl.

Share this post


Link to post
Share on other sites
It looks like that also happened with CheckAnswer_Cl1ck and NextQuestion_C1ick. Seems like a case of accidental l33t1ng while coding. [wink]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this