Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only assignment, call, increment, decrement, and new object expressions can be used as a statement and ; Expected

Tags:

c#

public string MessageItem (string ItemName)
{
    get { return dsMessageContents.Tables["input"].Rows[0].ToString();}
}

I am getting 2 errors:

  1. Only assignment, call, increment, decrements, and new object expressions can be used as a statement, and
  2. expected ;
like image 470
user2892711 Avatar asked Feb 06 '14 01:02

user2892711


2 Answers

You're combining a method and a property into something that... won't work. :)

Use a method:

public string MessageItem(string ItemName)
{
    return dsMessageContents.Tables["input"].Rows[0].ToString();
}

Or a property:

public string MessageItem
{
    get { return dsMessageContents.Tables["input"].Rows[0].ToString(); }
}

Read up on the differences here.

like image 192
Grant Winney Avatar answered Nov 19 '22 10:11

Grant Winney


This also happens if you use double == instead of single =.

string test;
test == "hello";

to

string test;
test = "hello";
like image 28
SSpoke Avatar answered Nov 19 '22 10:11

SSpoke