Only assignment, invocation, increment, decrement and new object expressions can be used as an operator

I am getting this error in the condiotional statement.

string remarks="";
AddDgvNew[6, i].Value==null?remarks="":remarks=AddDgvNew[6,i].Value.ToString();



source to share

2 answers


string remarks = AddDgvNew[6, i].Value==null?"":AddDgvNew[6,i].Value.ToString();




Yes - because you don't do anything with the result of the conditional expression. You have a conditional statement that tries to be an integer statement. In a simpler version:

bool condition = true;
int x = 10;
int y = 5;

// This is invalid
condition ? x : y;


What did you want to do with the result of the conditional expression? If point were to assign it to a variable, then you need to do that. Currently, you have two separate statements: one declares remarks

and assigns a value to it; the second is a conditional expression.

If you are trying to do something else, you need to clarify what you are looking for.



All Articles