我有一个event
,它返回boolean
。为了确保只有当有人在倾听时才会触发事件,我使用空条件运算符(questionmark)调用它。 但是,这意味着我必须将null-conditional运算符添加到返回的布尔值中。这意味着我无法弄清楚如何在if语句中使用它。有谁知道如何处理这个?if语句中的空条件布尔值
switch (someInt)
{
case 1:
// Validate if the form is filled correctly.
// The event returns true if that is the case.
bool? isValid = ValidateStuff?.Invoke();
if (isValid)
// If passed validation go to next step in form
GoToNextStep?.Invoke();
break;
// There are more cases, but you get the point
(...)
}
谢谢你的答案,我结束了使用'如果(isValid方法?假)',但我喜欢有几个不同选择的概念:-) – Noceo