I have been learning the Ternary operators and I have a problem, I have a variable, which if it is full it should print what is there, but if not then it should print the normal result of a query.
How can I pass the code below to a ternary operator?
I have the following code
if (MSJ != string.Empty)
{
return new JsonResult(MSJ);
}
else
{
return new JsonResult(DataTable);
}
The ternary operator ?: evaluates a boolean expression and returns the result of one of two expressions, depending on whether it is true or false .
In your case try this:
Here the expression is evaluated:
If true , the result value will be:
If false , the result value will be:
Finally it is done:
thus returning the value saved in result.