2 ms·
It gets rid of excessive nesting when you need multiple resources allocated after another (e.g. SqlConnection, SqlCommand, etc.). You can do using (han
by ygra 13y ago
It gets rid of excessive nesting when you need multiple resources allocated after another (e.g. SqlConnection, SqlCommand, etc.). You can do
using (handle a = new handle(0), b = new handle(1), c = handle(3)) {
// use a, b, c
}
instead, too, but that obviously only works with equal types.
I'm usually not a friend of too deep nesting (worst thing I've seen in our codebase was 65 spaces deep) and in C# you already have one level for the class, one for the namespace (possibly) and another for the method. No need to add two more if you can help it.
- dkuntz2 13y agoRight, I understand that it removes excessive nesting, but the first example just looked ... wrong to me. Your example with above looks somewhat better.