Null-coalescing operator and operator && in C#

Posted by abatishchev on Stack Overflow See other posts from Stack Overflow or by abatishchev
Published on 2010-04-27T22:20:03Z Indexed on 2010/04/27 22:23 UTC
Read the original article Hit count: 315

Is it possible to use together any way operator ?? and operator && in next case:

bool? Any
      var any = this.ViewState["any"] as bool?;
      return any.HasValue ? any.Value && this.SomeBool : any;

This means next:

  • if any is null then this.Any.HasValue return false
  • if any has value, then it returns value considering another boolean property, i.e. Any && SomeBool

© Stack Overflow or respective owner

Related posts about c#

Related posts about boolean-logic