Cannot Assign because it is a method group C#?

后端 未结 6 529
温柔的废话
温柔的废话 2021-01-01 17:02

Cannot Assign \"AppendText\" because it is a \"method group\".

public partial class Form1 : Form
{
    String text = \"\";

    public Form1()
    {
                 


        
相关标签:
6条回答
  • 2021-01-01 17:37

    You have to call the AppendText in this way:

    textBox1.AppendText("Some text")
    
    0 讨论(0)
  • 2021-01-01 17:47

    Use following

    textBox2.AppendText(text);
    

    Instead of

    textBox2.AppendText = text;
    

    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.

    0 讨论(0)
  • 2021-01-01 17:49

    Do this instead (AppendText is a method, not a property; which is exactly what the error message is telling you):

    textBox2.AppendText(text);
    
    0 讨论(0)
  • 2021-01-01 17:52

    I figured out that the variable name declared was similar to a method name and hence it didn't allow me to assign a value.
    The moment I changed the name it worked!

    0 讨论(0)
  • 2021-01-01 17:55

    AppendText is a method and you must call it.

    textBox2.AppendText(text);
    
    0 讨论(0)
  • 2021-01-01 17:59

    textBox2.AppendText(text); is a method. You have to call it like one. You were performing an assignment operation on a method.

    0 讨论(0)
提交回复
热议问题