我收到错误:
无法将类型十进制隐式转换为字符串
当我设置属性的值时,我不知道如何解决这个问题。
有两种形式。我将信息从一个表单传递到另一个表单以显示它。错误位于表单Price
表格(计算器):
public partial class Calculator : Form
{
decimal dorm = 0;
decimal meal = 0;
public Calculator()
{
InitializeComponent();
}
public decimal _price
{
get { return _price; }
}
private void getPriceButton_Click(object sender, EventArgs e)
{
decimal price = 0;
getInput();
price = dorm + meal;
Price myPrice = new Price();
myPrice._priceLabel = _price;
myPrice.ShowDialog();
}
private void getInput()
{
if(allenRadioButton.Checked)
{
dorm = 1500;
}
if(pikeRadioButton.Checked)
{
dorm = 1600;
}
if(farthingRadioButton.Checked)
{
dorm = 1800;
}
if(universityRadioButton.Checked)
{
dorm = 2500;
}
if(sevenRadioButton.Checked)
{
meal = 600;
}
if(fourteenRadioButton.Checked)
{
meal = 1200;
}
if(unlimitedRadioButton.Checked)
{
meal = 1700;
}
}
表格(价格):
public partial class Price : Form
{
public Price()
{
InitializeComponent();
}
public decimal _priceLabel
{
set { priceLabel.Text = value; } // error
}
priceLabel.Text = price.ToString("c"); //this is messed up too
}
}