Do short-circuiting operators || and && exist for nullable booleans? The RuntimeBinder sometimes thinks so

后端 未结 3 989
一整个雨季
一整个雨季 2021-01-30 01:31

I read the C# Language Specification on the Conditional logical operators || and &&, also known as the short-circuiting logical operat

3条回答
  •  死守一世寂寞
    2021-01-30 02:12

    The Nullable type does not define Conditional logical operators || and &&. I suggest you following code:

    bool a = true;
    bool? b = null;
    
    bool? xxxxOR = (b.HasValue == true) ? (b.Value || a) : a;
    bool? xxxxAND = (b.HasValue == true) ? (b.Value && a) : false;
    

提交回复
热议问题