Hi,
While discussing C#'s using statement, a guy and I had an argument.
In C# spec (15.13), there's an explanation like the following.
using (R r1 = new R()) {
r1.F();
}
is precisely equivalent to
R r1 = new R();
try {
r1.F();
}
finally {
if (r1 != null) ((IDisposable)r 1).Dispose();
}
I think that using statement is just a syntactic sugar.
But the guy doesn't think so.
He has a very narrow definition of syntactic sugar.
He says that doing the same thing doesn't mean it's a syntactic sugar.
He shows examples like the following.
a++ is a syntactic sugar for a = a + 1.
a[i] is a syntactic sugar for *(a + i) in C language.
I want to know what people think.
Would you call "using" statement a syntactic sugar?
If so, why?
If not, why not?
Thanks.
Sam
While discussing C#'s using statement, a guy and I had an argument.
In C# spec (15.13), there's an explanation like the following.
using (R r1 = new R()) {
r1.F();
}
is precisely equivalent to
R r1 = new R();
try {
r1.F();
}
finally {
if (r1 != null) ((IDisposable)r 1).Dispose();
}
I think that using statement is just a syntactic sugar.
But the guy doesn't think so.
He has a very narrow definition of syntactic sugar.
He says that doing the same thing doesn't mean it's a syntactic sugar.
He shows examples like the following.
a++ is a syntactic sugar for a = a + 1.
a[i] is a syntactic sugar for *(a + i) in C language.
I want to know what people think.
Would you call "using" statement a syntactic sugar?
If so, why?
If not, why not?
Thanks.
Sam
Comment