0

我正在研究一个decimalbinary converter控制台上完美运行的方法,然后我得到了关于我的核心数学运算的这些错误:

System.Windows.Forms.Button不包含定义,也找不到接受第一个类型参数的ToInt32扩展方法(您是否缺少 using 指令或程序集引用?) Line:93ToInt32System.Windows.Forms.Button

方法“ToString”没有重载需要 2 个参数 Line:94

System.Windows.Forms.Button 不包含“ToInt32”的定义,并且找不到接受“System.Windows.Forms.Button”类型的第一个参数的扩展方法“ToInt32”(您是否缺少 using 指令或装配参考?)行:103

这是代码:

    public void Convert_Click(object sender, EventArgs e)
    {
        string Input;
        bool IsNotBinary;
        string Answer;
        Start:
        Input = UserInput.Text;
        int InputLength = Input.Length;
        if (InputLength > 10)
        {
            UserInput.Text = "Overflow";
            goto Start;
        }
        int Int;
        bool IsANumber = int.TryParse(Input, out Int);
        if (IsANumber == false)
        {
            UserInput.Text = "Invalid Character";
            goto Start;
        }
        IsNotBinary = Input.Contains("3");
        if (IsNotBinary == true)
        {
            goto End;

        }
        IsNotBinary = Input.Contains("4");
        if (IsNotBinary == true)
        {
            goto End;

        }
        IsNotBinary = Input.Contains("5");
        if (IsNotBinary == true)
        {
            goto End;

        }
        IsNotBinary = Input.Contains("6");
        if (IsNotBinary == true)
        {
            goto End;

        }
        IsNotBinary = Input.Contains("7");
        if (IsNotBinary == true)
        {
            goto End;

        }
        IsNotBinary = Input.Contains("8");
        if (IsNotBinary == true)
        {
            goto End;

        }
        IsNotBinary = Input.Contains("9");
    End:

        if (IsNotBinary == true)
        {

            // decimal to binary
            int InputInt = Convert.ToInt32(Input); // converts the string "Input" to the int "InputInt"
            Answer = Convert.ToString(InputInt, 2);
            UserInput.Text = Answer;

        }

        else
        {

            // binary to decimal
            Answer = Convert.ToInt32(Input, 2).ToString();
            UserInput.Text = Answer;

        }
        Console.ReadLine();
        goto Start;
    }

    public void QuitButton_Click(object sender, EventArgs e)
    {
        Application.Exit();
    }        
}

}

4

1 回答 1

7

错误信息很清楚:

System.Windows.Forms.Button' 不包含 'ToInt32' 的定义

我的通灵调试器告诉我,您有一个名为 的类级别按钮变量Convert,因此您没有ToInt32在静态Convert类上调用该方法,因为您的按钮隐藏了它。重命名按钮或完全限定名称,即System.Convert.ToInt32().

编辑:

好吧,我想我毕竟不需要我的心理调试器。您的事件处理程序告诉我所有我需要知道的:

public void Convert_Click(...)
于 2012-08-13T03:44:21.357 回答