.net - What does "??" do in C#? -
this question has answer here:
- what 2 question marks mean in c#? 14 answers
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
Post a Comment