I found this new and interesting code in my project. What does it do, and how does it work?
MemoryStream stream = null;
MemoryStream st = stream ?? new MemoryStream();
A ?? B
is a shorthand for
if (A == null)
B
else
A
or more precisely
A == null ? B : A
so in the most verbose expansion, your code is equivalent to:
MemoryStream st;
if(stream == null)
st = new MemoryStream();
else
st = stream;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With