第二个帖子在这里,所以我最近开始了我的计算课程,我们正在研究 C# 我已经了解了一切,我们有我们应该从事的第一个项目,但是我在这里被难住了,我会向你展示整个代码供您阅读,然后我将在底部分离到发现错误的部分:
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 Calculator
{
public partial class Form1 : Form
{
string number;
public Form1()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void Number0_Click(object sender, EventArgs e)
{
number = number + "0";
CalcForm.Text = number;
}
private void Number1_Click(object sender, EventArgs e)
{
number = number + "1";
CalcForm.Text = number;
}
private void Number2_Click(object sender, EventArgs e)
{
number = number + "2";
CalcForm.Text = number;
}
private void Number3_Click(object sender, EventArgs e)
{
number = number + "3";
CalcForm.Text = number;
}
private void Number4_Click(object sender, EventArgs e)
{
number = number + "4";
CalcForm.Text = number;
}
private void Number5_Click(object sender, EventArgs e)
{
number = number + "5";
CalcForm.Text = number;
}
private void Number6_Click(object sender, EventArgs e)
{
number = number + "6";
CalcForm.Text = number;
}
private void Number7_Click(object sender, EventArgs e)
{
number = number + "7";
CalcForm.Text = number;
}
private void Number8_Click(object sender, EventArgs e)
{
number = number + "8";
CalcForm.Text = number;
}
private void Number9_Click(object sender, EventArgs e)
{
number = number + "9";
CalcForm.Text = number;
}
private void ButtonDecimal_Click(object sender, EventArgs e)
{
number = number + ".";
CalcForm.Text = number;
}
private void ButtonTimes_Click(object sender, EventArgs e)
{
string equation1 = CalcForm.Text;
double equation1int = Convert.ToDouble(equation1);
CalcForm.Text = "";
number = "";
string equation2 = CalcForm.Text;
double equation2int = Convert.ToDouble(equation2);
var equalsclicked = ButtonEquals_Click;
if (equalsclicked == true)
{
CalcForm.Text = "";
number = "";
double answer = equation1int * equation2int;
string answer1 = Convert.ToString(answer);
CalcForm.Text = answer1;
}
}
private void ButtonEquals_Click(object sender, EventArgs e)
{
}
}
}
所以,有表单代码,这里是错误,我将评论确切的行
{
string equation1 = CalcForm.Text;
double equation1int = Convert.ToDouble(equation1);
CalcForm.Text = "";
number = "";
string equation2 = CalcForm.Text;
double equation2int = Convert.ToDouble(equation2);
var equalsclicked = ButtonEquals_Click; //Here
if (equalsclicked == true) //Here
{
CalcForm.Text = "";
number = "";
double answer = equation1int * equation2int;
string answer1 = Convert.ToString(answer);
CalcForm.Text = answer1;
}
有错误,还有什么你可以看到的错误吗?还是优化明智?这仅用于乘法,但是一旦我这样做了,我就可以轻松地将其复制过来,谢谢:)