无法分配,因为它是 C# 方法组? [英] Cannot Assign because it is a method group C#?
本文介绍了无法分配,因为它是 C# 方法组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
无法分配AppendText",因为它是方法组".
Cannot Assign "AppendText" because it is a "method group".
public partial class Form1 : Form
{
String text = "";
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
String inches = textBox1.Text;
text = ConvertToFeet(inches) + ConvertToYards(inches);
textBox2.AppendText = text;
}
private String ConvertToFeet(String inches)
{
int feet = Convert.ToInt32(inches) / 12;
int leftoverInches = Convert.ToInt32(inches) % 12;
return (feet + " feet and " + leftoverInches + " inches." + "
");
}
private String ConvertToYards(String inches)
{
int yards = Convert.ToInt32(inches) / 36;
int feet = (Convert.ToInt32(inches) - yards * 36) / 12;
int leftoverInches = Convert.ToInt32(inches) % 12;
return (yards + " yards and " + feet + " feet, and " + leftoverInches + " inches.");
}
}
错误位于 button1_Click 方法内的textBox2.AppendText = text"行上.
The error is on the line "textBox2.AppendText = text", inside the button1_Click method.
推荐答案
使用以下
textBox2.AppendText(text);
代替
textBox2.AppendText = text;
AppendText
不是属性而是方法.因此需要带参数调用,不能直接赋值.
AppendText
is not a property but a method. Thus it needs to be invoked with parameter and cannot be assigned directly.
属性是特殊的方法,由于编译器中的特殊处理而支持赋值.
Properties are special methods, that support assignments due to special handling in compiler.
这篇关于无法分配,因为它是 C# 方法组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文