Click here to Skip to main content
15,896,730 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: c# Const vs. Readonly, Scope, Usings Pin
Foothill7-Jun-17 8:50
professionalFoothill7-Jun-17 8:50 
GeneralRe: c# Const vs. Readonly, Scope, Usings Pin
kalberts8-Jun-17 1:54
kalberts8-Jun-17 1:54 
GeneralRe: c# Const vs. Readonly, Scope, Usings Pin
dandy727-Jun-17 5:21
dandy727-Jun-17 5:21 
GeneralRe: c# Const vs. Readonly, Scope, Usings Pin
TheGreatAndPowerfulOz7-Jun-17 5:46
TheGreatAndPowerfulOz7-Jun-17 5:46 
GeneralRe: c# Const vs. Readonly, Scope, Usings Pin
dandy728-Jun-17 3:45
dandy728-Jun-17 3:45 
GeneralRe: c# Const vs. Readonly, Scope, Usings Pin
kalberts8-Jun-17 2:21
kalberts8-Jun-17 2:21 
GeneralRe: c# Const vs. Readonly, Scope, Usings Pin
dandy728-Jun-17 3:44
dandy728-Jun-17 3:44 
GeneralRe: c# Usings Pin
irneb8-Jun-17 5:07
irneb8-Jun-17 5:07 
What's so wrong with it?

If you don't like the idea, you could always just:
C#
var someObject = new MyDisposableObject();
// Do some work with it
someObject.Dispose();

The trouble with that is, if the code never reaches that Dispose line, it won't get called. In which case you then incorporate it into a try-finally block like so:
C#
var someObject = new MyDisposableObject();
try {
   // Do some work with it
}
finally {
   someObject.Dispose();
}

But ... that's exactly what a using clause does for you ... just a whole lot less coding on your side:
C#
using (var someObject = new MyDisposableObject()) {
   // Do some work with it
}

I might have liked an idea where you could add numerous unrelated disposables into the using clause - this may alleviate nesting usings. Though take note that with nesting you've got some control over the order in which they're disposed. Also some disposables are contained in other disposables, and in most such cases disposing the container does so to its contents as well, meaning you only need dispose the final container --> only one using clause.

More of an issue for me is the fact that a destructor isn't called deterministically, if at all. If such were possible, then the dispose pattern could be moved into the destructor instead of a dispose method. And even if you forget to dispose it, it would finally happen once the GC frees it from resources. Though this means the entire GC idea needs a revamp, in fact some of C#'s creators also think this is one of the biggest mistakes in the entire DotNet, just that they do know the reasons such choice was made.
GeneralRe: c# Const vs. Readonly Pin
irneb8-Jun-17 5:14
irneb8-Jun-17 5:14 
GeneralRe: c# Const parameters Pin
irneb8-Jun-17 5:27
irneb8-Jun-17 5:27 
GeneralRe: c# Scope in properties Pin
irneb8-Jun-17 5:30
irneb8-Jun-17 5:30 
GeneralRe: c# Const vs. Readonly, Scope, Usings Pin
Caslen9-Jun-17 8:36
Caslen9-Jun-17 8:36 
GeneraliOS 11 can automatically delete apps to save space Pin
ZurdoDev7-Jun-17 3:24
professionalZurdoDev7-Jun-17 3:24 
GeneralRe: iOS 11 can automatically delete apps to save space Pin
harold aptroot7-Jun-17 3:35
harold aptroot7-Jun-17 3:35 
GeneralRe: iOS 11 can automatically delete apps to save space Pin
lopatir7-Jun-17 3:37
lopatir7-Jun-17 3:37 
GeneralRe: iOS 11 can automatically delete apps to save space Pin
ZurdoDev7-Jun-17 3:39
professionalZurdoDev7-Jun-17 3:39 
GeneralRe: iOS 11 can automatically delete apps to save space Pin
  Forogar  7-Jun-17 3:47
professional  Forogar  7-Jun-17 3:47 
GeneralRe: iOS 11 can automatically delete apps to save space Pin
OriginalGriff7-Jun-17 3:56
mveOriginalGriff7-Jun-17 3:56 
GeneralRe: iOS 11 can automatically delete apps to save space Pin
megaadam7-Jun-17 4:27
professionalmegaadam7-Jun-17 4:27 
GeneralRe: iOS 11 can automatically delete apps to save space Pin
Chris Maunder7-Jun-17 4:49
cofounderChris Maunder7-Jun-17 4:49 
GeneralRe: iOS 11 can automatically delete apps to save space Pin
ZurdoDev7-Jun-17 4:52
professionalZurdoDev7-Jun-17 4:52 
GeneralRe: iOS 11 can automatically delete apps to save space Pin
Chris Maunder7-Jun-17 4:55
cofounderChris Maunder7-Jun-17 4:55 
GeneralRe: iOS 11 can automatically delete apps to save space Pin
Nelek7-Jun-17 5:38
protectorNelek7-Jun-17 5:38 
GeneralRe: iOS 11 can automatically delete apps to save space Pin
dandy727-Jun-17 5:12
dandy727-Jun-17 5:12 
GeneralRe: iOS 11 can automatically delete apps to save space Pin
ZurdoDev7-Jun-17 5:16
professionalZurdoDev7-Jun-17 5:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.