Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法隐式转换类型";int";至;System.EventArgs“;?_C# - Fatal编程技术网

C# 无法隐式转换类型";int";至;System.EventArgs“;?

C# 无法隐式转换类型";int";至;System.EventArgs“;?,c#,C#,我是C#的新用户,我正在尝试做一些简单的基本游戏来掩盖基本的东西。我以前学过python,对编码也很熟悉。我的问题是我无法将一些按钮转换为“int”。某些按钮可以转换,但按钮(bn1、bn2、bn3…)不可转换,并给出错误信息。如果我使用Convert.ToInt32(bn1.Text),但如果我尝试使用e=Convert.ToInt32(bn1.Text),它不工作。我怎样才能解决这个问题 using System; using System.Collections.Generic; usin

我是C#的新用户,我正在尝试做一些简单的基本游戏来掩盖基本的东西。我以前学过python,对编码也很熟悉。我的问题是我无法将一些按钮转换为“int”。某些按钮可以转换,但按钮(bn1、bn2、bn3…)不可转换,并给出错误信息。如果我使用
Convert.ToInt32(bn1.Text),但如果我尝试使用
e=Convert.ToInt32(bn1.Text),它不工作。我怎样才能解决这个问题

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        int say1, say2, say3, say4, say5, say6, say7, say8, say9;
        int a, b, c, d,e,f,g;


    int say = 0;
    float klm = 0;
    Random rastgele = new Random();
    private void Form1_Load(object sender, EventArgs e)
    {

    }

    private void islem()
    {

    }

    private void PLAYY_Click(object sender, EventArgs e)
    {
        timer1.Enabled = true;
        BT1.Text = rastgele.Next(1, 10).ToString();
        BT2.Text = rastgele.Next(1, 10).ToString();
        BT3.Text = rastgele.Next(1, 10).ToString();
        BT4.Text = rastgele.Next(1, 10).ToString();
        BT5.Text = rastgele.Next(1, 10).ToString();
        BT6.Text = rastgele.Next(1, 10).ToString();

        QUEMARK.Text = rastgele.Next(25, 100).ToString();
        TARGETBT.Text = rastgele.Next(100, 1000).ToString();

    }

    private void EXITT_Click(object sender, EventArgs e)
    {
        this.Close();
    }

    private void BT1_Click(object sender, EventArgs e)
    {   
        a = Convert.ToInt32(BX1.Text);
        b = Convert.ToInt32(BX2.Text);
        c = Convert.ToInt32(BX3.Text);
        d = Convert.ToInt32(BX4.Text);
        e = Convert.ToInt32(bn1.Text);


        if (a == 0)
        {
            BX1.Text = BT1.Text;
            BT1.Enabled = false;
            BT1.BackColor = Color.Yellow;

        }
        if (a > 0)
        {
            if (Convert.ToInt32(bn1.Text) == 0) 
            {
                bn1.Text = BT1.Text;
                BT1.Enabled = false;
                BT1.BackColor = Color.Yellow;
            }

            else
            {
                BX2.Text = BT1.Text;
                BT1.Enabled = false;
                BT1.BackColor = Color.Azure;
            }
        }

    }


 }

方法BT1\u Click包含一个名为e的参数,类型为EventArgs

在方法的主体中,有另一个名为e的变量,您希望将
Convert.ToInt32(bn1.Text)赋值到该变量中

要实现您想要做的事情,您需要引用类变量e,即“this”

用作限定符,表示您指的是类字段
e
,而不是传递到方法中的参数
e

this.e = Convert.ToInt32(bn1.Text);

或者,您可以为方法参数
e
指定不同的名称,如
args

private void BT1_Click(object sender, EventArgs args)

使用
intmynumber=Int32.Parse(txtSomeTextBox.Text)

你有两个不同的名字叫
e
;您没有将按钮转换为int;您正在将按钮的文本转换为int。侧注:请阅读关于发布代码的指南-发布代码墙,因为不欢迎提出问题。
private void BT1_Click(object sender, EventArgs args)