ASP.NET Core 2 High Performance(Second Edition)
上QQ阅读APP看书,第一时间看更新

Null conditional

The null conditional operator is a way of simplifying null checks. You can now place an inline check for null rather than use an if statement or ternary operator. This makes it easier to use in more places and will hopefully help you avoid the dreaded null reference exception.

You can avoid doing a manual null check, as in the following code:

int? length = (null == bytes) ? null : (int?)bytes.Length;

This can now be simplified to the following statement by adding a question mark:

int? length = bytes?.Length;