继续作为简明中的第一个声明

Bas*_*sie 1 .net c# if-statement visual-studio-2015

我在foreach循环中有以下if else语句:

string date = GetDate(item)
if (date == null)
{
    continue;
}
else
{
    article.Date = date;
}
Run Code Online (Sandbox Code Playgroud)

我想用简明的格式写这个? ::

string date = GetDate(item)
date == null ? continue : article.Date = date;
Run Code Online (Sandbox Code Playgroud)

我收集,这应该工作,因为它是在格式condition ? first_expression : second_expression;,这里first_expressioncontinue,但是在Visual Studio 2015年我看到这些错误的特定领域:

继续

无效的表达式术语'继续'

语法错误,':'预期

无效的表达式术语'继续'

; 预期

:

; 预期

:预期

是否有可能continue在这类型中使用If/Else?如果没有,这有什么理由吗?

RJF*_*ner 5

https://msdn.microsoft.com/en-gb/library/ms173144.aspx

表达式是一个或多个操作数以及零个或多个运算符的序列,可以将它们计算为单个值,对象,方法或命名空间

continue 不是表达

您的代码正在尝试分配continue给您的"日期"变量.这没有意义.我担心没有办法使用三元运算符来实现你想要完成的任务.