-1

Error CS0201 Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement

the code =

private void addIntel(string label, string kind, string detail, string insertText)
        {
            "\"" + label + "\"";
            "\"" + kind + "\"";
            "\"" + detail + "\"";
            "\"" + insertText + "\"";
            this.webBrowser1.Document.InvokeScript("AddIntellisense", new object[]
            {
                label,
                kind,
                detail,
                insertText
            });
        }
jps
  • 20,041
  • 15
  • 75
  • 79
xColth
  • 1
  • 1
  • 5
    Sure. What is `"\"" + label + "\"";` supposed to be, in your view? What do you think line line (and the 3 lines below it) are actually doing? It's just a string on its own. You're not using it for anything, and it's not valid C# by itself. You'd need to **do** something, like assign the result of that string operation to a variable. I suggest you study some basic C# tutorials - or take another look at them, if you've already done that. – ADyson Jul 13 '20 at 10:35
  • The thing compiler is pointing at is that expressions like `"\"" + label + "\"";` are operator invocation, which can't be used by itself - it can be only right-hand side of assignment, or a method argument, and so on. Assign that to something (possibly, you intended to do `label = "\"" + label + "\""`) – Андрей Саяпин Jul 13 '20 at 10:37

3 Answers3

1

This "\"" + label + "\""; is a statement which doesn't call anything, doesn't assign anything and doesn't create any new objects. That is what the error is all about. I'm guessing that what you want to do is to add quotation marks around your values, but to do so you also need to assign the result back to your variables, like this.

label = "\"" + label + "\"";
kind = "\"" + kind + "\"";
detail = "\"" + detail + "\"";
insertText = "\"" + insertText + "\"";
Karl-Johan Sjögren
  • 16,544
  • 7
  • 59
  • 68
1

The first line of your function (for example) says this:

"\"" + label + "\"";

But maybe it should say

label = "\"" + label + "\"";

That will convert it from a pure string expression to a statement. Statements do something; in this example compute a value of some sort and then do something with it, store it back into the original variable.

O. Jones
  • 103,626
  • 17
  • 118
  • 172
0

If you are getting this because of CSharp Scripting Nuget, take a look at this so answer.

VivekDev
  • 20,868
  • 27
  • 132
  • 202