.net - What does "??" do in C#? -


this question has answer here:

i found new , interesting code in project. do, , how work?

memorystream stream = null; memorystream st = stream ?? new memorystream(); 

a ?? b 

is shorthand

if (a == null)      b else      

or more precisely

a == null ? b : 

so in verbose expansion, code equivalent to:

memorystream st; if(stream == null)     st = new memorystream(); else     st = stream; 

Comments

Popular posts from this blog

android - Inheriting from Theme.AppCompat* -

broadcastreceiver - android BOOT_COMPLETED not received if not activity intent-filter -

basic authentication with http post params android -