C# 只有赋值、调用、递增、递减、等待和新对象表达式可以用作错误C语句#
当我试图创建一个float并在创建它之后设置它的值时,我遇到了一个错误,我得到了这个错误。我对正在发生的事情感到非常困惑,因为它与上面的代码相同,除了它是一个浮点。这是我的密码C# 只有赋值、调用、递增、递减、等待和新对象表达式可以用作错误C语句#,c#,.net,C#,.net,当我试图创建一个float并在创建它之后设置它的值时,我遇到了一个错误,我得到了这个错误。我对正在发生的事情感到非常困惑,因为它与上面的代码相同,除了它是一个浮点。这是我的密码 using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Thread
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 Sale_Tracker
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string DOW;
private void ComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
DOW = comboBox1.Text;
}
int carrotSales;
float carrotEarnings;
private void Add1_Click(object sender, EventArgs e)
{
carrotSales++;
carrotEarnings + 1.50; //error is here
writeTotal1();
writeEarnings1();
}
void writeTotal1()
{
total1.Text = "Total: " + carrotSales;
}
void writeEarnings1()
{
earnings1.Text = "Earnings: $" + carrotEarnings;
}
int gAppleSales;
private void Add2_Click(object sender, EventArgs e)
{
gAppleSales++;
writeTotal2();
}
void writeTotal2()
{
total2.Text = "Total: " + gAppleSales;
}
}
}
我已经尝试在那里添加一个1.50f
,但它没有修复它
任何帮助都很好。非常感谢。替换您的函数Add1\u单击如下所示
private void Add1_Click(object sender, EventArgs e)
{
carrotSales++;
carrotEarnings = carrotEarnings + 1.50; //error is here
writeTotal1();
writeEarnings1();
}
您已经初始化了浮点变量 浮动收益 在不初始化变量值的情况下,您正在尝试增加变量。初始化变量,如下所示 浮动收益=0.0f
do
carrogenders=carrogenders+1.50f
或胡萝卜收益+=1.50f
。您是否更改胡萝卜收益+1.50;要获得收益+=1.50f;?