Allow using(idisposable) to be used as a boolean in an expression #4643
Unanswered
wiz0u
asked this question in
Language Ideas
Replies: 2 comments 4 replies
-
Other than your particular desire to dispose of the object after the last if (stream is not null) using (stream)
{
stream.CopyTo(destination);
}
else
Console.WriteLine("stream was null"); |
Beta Was this translation helpful? Give feedback.
2 replies
-
Allowing more things in |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I feel like it would be nice to be allowed to write statement like:
What this would mean, is that
using
is considered as an expression returning true if stream is non-null (i.e. an IDisposable), and false if stream is null.It also mean that the IDisposable gets dispose at the end of the full statement block (if-else), or at the end of the current statement if that expression is not part of a control-flow statement.
(of course, if stream is null, there is nothing to dispose, just like using(nullValue) is already accepted now and does nothing)
What do you think?
Beta Was this translation helpful? Give feedback.
All reactions