Skip to content

Null-coalescing operator C# 2.0code reductionreadability

Provide a value when an expression is null.

Alongside nullable value types C# 2.0 a new ?? operator was added to make working with nulls easier.

Code

C#
intro = post.Intro ?? MakeIntro(post);
C#
intro = post.Intro != null ? post.Intro : MakeIntro(post);

Notes

More information