.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

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -