![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Why doesn't 'using' command allow multiple objects? Israel <israeldiperi@xxxxxx> wrote: Quote: > On Jun 26, 3:42*pm, Jon Skeet [C# MVP] <sk...@xxxxxx> wrote: Quote: > > Why not just nest using statements? > preference reasons but also because if had two disposable objects used > within an area and then later changed that to 3 and only added a > single line within that region then the file would look like I made a > whole bunch of changes to many lines (unless I ignored whitespace > changes) because it had to indent a bunch of code. At what point does > the indentation become overwelming? 5, 6 or 7 levels? refactoring IMO. However, with pretty wide monitors these days line limits aren't what they were. I try to avoid having too much *non-whitespace* per line, but having a reasonably large indentation doesn't bother me much. I've also found that changing indentation to 2 spaces instead of 4 makes code a lot nicer to read. Quote: Quote: > > Alternatively, you don't need the outer braces - using statements stack > > nicely: > statement works. I guess that's another personal thing but I always > make it a policy to never use 'if' statements without braces because > it scares me; the conditional code isn't properly contained with its > own scope and could spill out all over the place Also it was a> coding standard at my first job out of college and I guess it just > stuck with me. too, but then I don't mind the indentation. Quote: Quote: > > You should be aware, by the way, that the using statement isn't like a > > normal method - it's a language construct. > I guess that's why I figured they could have easily done whatever they > wanted when they first created C# since C++ doesn't have anything like > that. Was 'using' barrowed from VB6? Or was that a different using > because they didn't have the concept of dispose before .NET. they potentially could have made it declare more than one variable, but I don't see it as a significant flaw that they didn't. -- Jon Skeet - <skeet@xxxxxx> Web site: http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon_skeet C# in Depth: http://csharpindepth.com |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Why doesn't 'using' command allow multiple objects? Israel <israeldiperi@xxxxxx> wrote: Quote: > I always wondered why the using command can only take one object. types. Quote: > I always find that this isn't sufficient for drawing so I end up always > disposing in my finally block but then I have to remember to put > everything in there. using (Pen mypen = new Pen(Color.Black)) { using (Brush mybrush = new SolidBrush(Color.Blue)) { } } Alternatively, you don't need the outer braces - using statements stack nicely: using (Pen mypen = new Pen(Color.Black)) using (Brush mybrush = new SolidBrush(Color.Blue)) { } You should be aware, by the way, that the using statement isn't like a normal method - it's a language construct. -- Jon Skeet - <skeet@xxxxxx> Web site: http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon_skeet C# in Depth: http://csharpindepth.com |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Why doesn't 'using' command allow multiple objects? On Jun 26, 3:42*pm, Jon Skeet [C# MVP] <sk...@xxxxxx> wrote: Quote: > Why not just nest using statements? preference reasons but also because if had two disposable objects used within an area and then later changed that to 3 and only added a single line within that region then the file would look like I made a whole bunch of changes to many lines (unless I ignored whitespace changes) because it had to indent a bunch of code. At what point does the indentation become overwelming? 5, 6 or 7 levels? Quote: > Alternatively, you don't need the outer braces - using statements stack > nicely: statement works. I guess that's another personal thing but I always make it a policy to never use 'if' statements without braces because it scares me; the conditional code isn't properly contained with its own scope and could spill out all over the place Also it was acoding standard at my first job out of college and I guess it just stuck with me. Quote: > You should be aware, by the way, that the using statement isn't like a > normal method - it's a language construct. wanted when they first created C# since C++ doesn't have anything like that. Was 'using' barrowed from VB6? Or was that a different using because they didn't have the concept of dispose before .NET. |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Why doesn't 'using' command allow multiple objects? Israel <israeldiperi@xxxxxx> wrote: Quote: > On Jun 26, 3:42*pm, Jon Skeet [C# MVP] <sk...@xxxxxx> wrote: Quote: > > Why not just nest using statements? > preference reasons but also because if had two disposable objects used > within an area and then later changed that to 3 and only added a > single line within that region then the file would look like I made a > whole bunch of changes to many lines (unless I ignored whitespace > changes) because it had to indent a bunch of code. At what point does > the indentation become overwelming? 5, 6 or 7 levels? refactoring IMO. However, with pretty wide monitors these days line limits aren't what they were. I try to avoid having too much *non-whitespace* per line, but having a reasonably large indentation doesn't bother me much. I've also found that changing indentation to 2 spaces instead of 4 makes code a lot nicer to read. Quote: Quote: > > Alternatively, you don't need the outer braces - using statements stack > > nicely: > statement works. I guess that's another personal thing but I always > make it a policy to never use 'if' statements without braces because > it scares me; the conditional code isn't properly contained with its > own scope and could spill out all over the place Also it was a> coding standard at my first job out of college and I guess it just > stuck with me. too, but then I don't mind the indentation. Quote: Quote: > > You should be aware, by the way, that the using statement isn't like a > > normal method - it's a language construct. > I guess that's why I figured they could have easily done whatever they > wanted when they first created C# since C++ doesn't have anything like > that. Was 'using' barrowed from VB6? Or was that a different using > because they didn't have the concept of dispose before .NET. they potentially could have made it declare more than one variable, but I don't see it as a significant flaw that they didn't. -- Jon Skeet - <skeet@xxxxxx> Web site: http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon_skeet C# in Depth: http://csharpindepth.com |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Selecting one from multiple similar objects | PowerShell | |||
| get multiple wmi objects one query | PowerShell | |||
| ADO.Net / Multiple SQL Statements in One Command | .NET General | |||
| Modifying multiple AD user objects | PowerShell | |||