Click here to Skip to main content
15,917,456 members
Home / Discussions / C#
   

C#

 
GeneralRe: a mask control in windows form application Pin
jokercocol15-Jul-12 6:59
jokercocol15-Jul-12 6:59 
GeneralRe: a mask control in windows form application Pin
Dave Kreskowiak15-Jul-12 12:02
mveDave Kreskowiak15-Jul-12 12:02 
Questionmake a database in C# Pin
messages14-Jul-12 3:54
messages14-Jul-12 3:54 
AnswerRe: make a database in C# Pin
PIEBALDconsult14-Jul-12 4:10
mvePIEBALDconsult14-Jul-12 4:10 
GeneralRe: make a database in C# Pin
messages14-Jul-12 4:17
messages14-Jul-12 4:17 
GeneralRe: make a database in C# Pin
Wes Aday14-Jul-12 4:46
professionalWes Aday14-Jul-12 4:46 
GeneralRe: make a database in C# Pin
messages14-Jul-12 5:14
messages14-Jul-12 5:14 
GeneralRe: make a database in C# Pin
Wes Aday14-Jul-12 5:32
professionalWes Aday14-Jul-12 5:32 
AnswerRe: make a database in C# Pin
Paul Conrad14-Jul-12 15:14
professionalPaul Conrad14-Jul-12 15:14 
GeneralRe: make a database in C# Pin
PIEBALDconsult14-Jul-12 18:15
mvePIEBALDconsult14-Jul-12 18:15 
QuestionWhy Using during Sql Server Connection Pin
munishk14-Jul-12 3:11
munishk14-Jul-12 3:11 
AnswerRe: Why Using during Sql Server Connection Pin
Eddy Vluggen14-Jul-12 3:35
professionalEddy Vluggen14-Jul-12 3:35 
GeneralRe: Why Using during Sql Server Connection Pin
jschell14-Jul-12 6:55
jschell14-Jul-12 6:55 
GeneralRe: Why Using during Sql Server Connection Pin
munishk14-Jul-12 18:59
munishk14-Jul-12 18:59 
GeneralRe: Why Using during Sql Server Connection Pin
PIEBALDconsult15-Jul-12 7:30
mvePIEBALDconsult15-Jul-12 7:30 
GeneralRe: Why Using during Sql Server Connection Pin
jschell15-Jul-12 7:30
jschell15-Jul-12 7:30 
AnswerRe: Why Using during Sql Server Connection Pin
Wes Aday14-Jul-12 3:36
professionalWes Aday14-Jul-12 3:36 
AnswerRe: Why Using during Sql Server Connection PinPopular
OriginalGriff14-Jul-12 3:43
mveOriginalGriff14-Jul-12 3:43 
using is not just for unmanaged code - in fact I almost never write unmanaged code, and I use using all the time.

What is does is ensure that the object created in the using block header is Disposed at the end, exactly as if it had been written as
C#
MyObject mo = new MyObject();
...
mo.Dispose():
In fact, a using block is just a syntactic sugar for just that, but with the added advantage that it terminates the scope of the variable as well, so you can't accidentally use the Disposed object.

Why do I use it? It's clean, it's clear, and it de-scopes a variable when I can't use it again.
Why is it important to Dispose managed objects? Because some of them hold resources: for example, Bitmaps, Files and so forth hang on to resources such as handles and file access locks until the object is disposed - in the case of a Bitmap it is not at all obvious that:
C#
Image i = Image.FromFile(path);
puts a file access lock on the image source file until the image is Disposed. So if you use this to load an image, let the user modify it and then try to save it again, the file may or may not still be in use...annoying. Surrounding the Image creating with a using block removes this problem.

If an object supports IDisposable, then Dispose should be called on it. And a using block is the easiest, cleanest way to do that.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

AnswerRe: Why Using during Sql Server Connection Pin
Luc Pattyn14-Jul-12 7:18
sitebuilderLuc Pattyn14-Jul-12 7:18 
AnswerRe: Why Using during Sql Server Connection Pin
PIEBALDconsult15-Jul-12 7:39
mvePIEBALDconsult15-Jul-12 7:39 
GeneralLooking for Volunteers Pin
Santa's Little Helper14-Jul-12 3:04
Santa's Little Helper14-Jul-12 3:04 
GeneralRe: Looking for Volunteers Pin
Eddy Vluggen14-Jul-12 3:37
professionalEddy Vluggen14-Jul-12 3:37 
GeneralRe: Looking for Volunteers Pin
Santa's Little Helper14-Jul-12 3:50
Santa's Little Helper14-Jul-12 3:50 
QuestionUI For C# Pin
atoi_powered13-Jul-12 10:23
atoi_powered13-Jul-12 10:23 
AnswerRe: UI For C# Pin
fjdiewornncalwe13-Jul-12 10:46
professionalfjdiewornncalwe13-Jul-12 10:46 

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.