Operators
using without explicit curly braces applies only to the following statement.
using (Idisp1)
Thus, when confined, they work the same way. The second using here acts as a single statement.
using (Idisp1) using (Idisp2) { }
Comment stakx suggested that formatting make it clear how the compiler reads usage blocks. In fact, they are usually formatted as detected by the OP:
using (Idisp1) using (Idisp2) { }
This is equivalent to this:
using (Idisp1) { using (Idisp2) { } }
Please note that the first at the top is always the last to be posted. Thus, in all previous examples, Idisp2.Dispose() is called before Idisp1.Dispose() . This does not apply in many cases when you do something similar, but I believe that you should always know what your code will do and make an informed decision not to care.
An example of this is reading a web page:
HttpWebRequest req = ...; using (var resp = req.GetResponse()) using (var stream = resp.GetResponseStream()) using (var reader = new StreamReader(stream)) { TextBox1.Text = reader.ReadToEnd();
We get the answer, get the stream, get the reader, read the stream, delete the reader, delete the stream, and finally delete the answer.
Note that commentator Nikhil Agrawal noted that this is a language function related to blocks not related to the using keyword. For example, the same applies to if blocks:
if (condition) // may or may not execute // definitely will execute
Vs
if (condition1) if (condition2)
Although you should never, of course, use if in a way that is terrible to read, but I thought it would help you understand the using case. I am personally very good with using chains.