Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can the C# using statement be written without the curly braces?

I was browsing a coworkers c# code today and found the following:

    using (MemoryStream data1 = new MemoryStream())     using (MemoryStream data2 = new MemoryStream())     {         // Lots of code..........      } 

I had always seen the using statement followed by a pair of curly braces that defined the scope of the object life. My coworker who wrote the code said that the curly braces for the data1 using statement weren't needed and the code did the same thing as if they were present and nested the data2 using statement. So, what happens when the curly braces are ommitted?

like image 619
DaveB Avatar asked Aug 17 '10 20:08

DaveB


People also ask

Does Can-C help with macular degeneration?

Can-C's ingredients help to soothe and rejuvenate tired eyes, help with macular degeneration, cataracts and other age related eye disorders.

Does Can-C work for cataracts?

By managing cataracts with Can-C, some patients may be able to avoid cataract surgery and keep their own natural lens. Cataract surgery is an in-office or outpatient procedure done without the need for general anesthetic. The diseased lens is removed and replaced.

Can-C eye drops be used?

Benefits of C-Nac Eye Drop C-Nac Eye Drop adds moisture to your eyes and keeps them lubricated. This gives relief from burning sensation and discomfort due to dryness of the eyes. C-Nac Eye Drop also reduces infection and irritation in the eye.

How often can you use can-c eye drops?

Use this medication in the affected eye(s) up to 4 times a day as needed or as directed by your doctor. Tilt your head back, look upward, and pull down the lower eyelid to make a pouch. Hold the dropper directly over the eye and place 1 drop into the pouch. Look downward and gently close your eyes for 1 to 2 minutes.


1 Answers

Yes, you can also put them in one using statement:

using (MemoryStream data1 = new MemoryStream(),                      data2 = new MemoryStream()) {     // do stuff } 
like image 181
Albin Sunnanbo Avatar answered Sep 22 '22 01:09

Albin Sunnanbo