The ?? Operator

Something I have been seeing more and more of lately is the ?? Operator also known as Null coalescing operator.

It’s great for assigning values when dealing with nullable types.

int pageSize = (page ?? 1);

So if page is null, then give pageSize a value of 1. If page is not null then give pageSize the value of page.

You can also string the ?? Operator together.

string Question = Q1 ?? Q2 ?? Q3 ?? Q4;

Source: What do two question marks together mean in C#?

Advertisements

Published by

Alan Feekery

Developer, Gamer, Musician, Cyclist and big Motorsport fan... enjoys the odd cup of coffee :)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s