嗨,我写这些代码是因为我需要做一个条件(如您所见)。但它突出显示的地方。给出此错误消息的意思是:
当前上下文中不存在名称“ A”
名字“B” does not existi n the current context
C#:
using System;
using System.Windows.Form
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void txtResultA_TextChanged(object sender, EventArgs e)
{
if (!string.IsNullOrWhiteSpace(txtResultA.Text) && !string.IsNullOrWhiteSpace(txtResultB.Text))
{
float A = 0;
float B = 0;
float.TryParse(txtResultA.Text, out A);
float.TryParse(txtResultB.Text, out B);
if (A > B)
{
txt_SoldForResultA.Text = (A - B).ToString("N2");
txt_SoldForResultB.Text = string.Empty;
}
else if (A < B)
{
txt_SoldForResultB.Text = (B - A).ToString("N2");
txt_SoldForResultA.Text = string.Empty;
}
}
}
private void txtResultB_TextChanged(object sender, EventArgs e)
{
txtResultA_TextChanged(sender, e);
}
}
}
由主持人最后编辑: