lundi 1 août 2016

Continue as First Statement in Concise If Else

I have the following if else statement inside of a foreach loop:

string date = GetDate(item)
if (date == null)
{
    continue;
}
else
{
    article.Date = date;
}

And I would like to write this in the concise format using ? ::

string date = GetDate(item)
date == null ? continue : article.Date = date;

From what I gather, this should work, as it is in the format condition ? first_expression : second_expression;, where first_expression is continue, however in Visual Studio 2015 I am seeing these errors for the given areas:

continue

Invalid expression term 'continue'

Syntax error, ':' expected

Invalid expression term 'continue'

; expected

:

; expected

: expected

Is it possible to use continue in this types of If/Else? If not, is there any reason for this?

Aucun commentaire:

Enregistrer un commentaire