Click here to Skip to main content
15,911,762 members
Home / Discussions / C#
   

C#

 
AnswerRe: using statement Vs Dispose/Finalize pattern Pin
Christian Graus30-Jul-09 22:00
protectorChristian Graus30-Jul-09 22:00 
GeneralRe: using statement Vs Dispose/Finalize pattern Pin
N a v a n e e t h30-Jul-09 22:07
N a v a n e e t h30-Jul-09 22:07 
AnswerRe: using statement Vs Dispose/Finalize pattern Pin
N a v a n e e t h30-Jul-09 22:04
N a v a n e e t h30-Jul-09 22:04 
GeneralRe: using statement Vs Dispose/Finalize pattern Pin
Cracked-Down30-Jul-09 22:59
Cracked-Down30-Jul-09 22:59 
GeneralRe: using statement Vs Dispose/Finalize pattern Pin
Not Active30-Jul-09 23:46
mentorNot Active30-Jul-09 23:46 
GeneralRe: using statement Vs Dispose/Finalize pattern Pin
Cracked-Down30-Jul-09 23:58
Cracked-Down30-Jul-09 23:58 
GeneralRe: using statement Vs Dispose/Finalize pattern Pin
PIEBALDconsult31-Jul-09 4:58
mvePIEBALDconsult31-Jul-09 4:58 
GeneralRe: using statement Vs Dispose/Finalize pattern Pin
N a v a n e e t h31-Jul-09 7:02
N a v a n e e t h31-Jul-09 7:02 
SaveTigers wrote:
I just wanted to see if there are some other differences other than which I have mentioned!


Points mentioned by you are correct. It all depends on your object's lifetime. You can use using block when your object have very small lifetime, say in a function.

Consider the example 1 provided in your first post. I assume you have your word wrapper class used in a windows form.
class WordOperations : Form
{

    WordWrapper wrapper = /* ... */

    protected override void Dispose(bool disposing)
    {
        wrapper.Dispose();
        /* ...... */
    }

}
In the above example, we have used form's dispose method to dispose your word wrapper. This will help you to *avoid* the finalization. Now a user of your form can use it like
using(WordOperations op = new WordOperations())
{
    op.ShowDialog();
}
This will ensure the disposal of form and the wrapper.

Finalization has a cost and try to avoid it when possible. So, if you own the code base, there is no need to implement a finalizer on the wrapper class. Just make sure you call Dispose().

SaveTigers wrote:
Apart from that, what exactly pattern? its only some set of standard which anybody can define( with some advantage), so saying something like this that Using is not pattern and cant be compared with Dispose/Finalize pattern will be a harsh!! isn't it?


No.

Implementing IDisposable in a recommended way is called as dispose pattern. using is just a syntactic sugar to ease the use of disposable objects. Read Implementing IDisposable and the Dispose Pattern Properly[^] to get a good understanding about this.

Smile | :)


GeneralRe: using statement Vs Dispose/Finalize pattern Pin
Cracked-Down31-Jul-09 19:46
Cracked-Down31-Jul-09 19:46 
QuestionHow to have more than one key and one value in any structure(like hash table) in C#? Pin
akashsthakkar30-Jul-09 20:46
akashsthakkar30-Jul-09 20:46 
AnswerRe: How to have more than one key and one value in any structure(like hash table) in C#? [modified] Pin
dan!sh 30-Jul-09 20:50
professional dan!sh 30-Jul-09 20:50 
AnswerRe: How to have more than one key and one value in any structure(like hash table) in C#? Pin
PIEBALDconsult30-Jul-09 20:59
mvePIEBALDconsult30-Jul-09 20:59 
AnswerRe: How to have more than one key and one value in any structure(like hash table) in C#? Pin
N a v a n e e t h30-Jul-09 22:10
N a v a n e e t h30-Jul-09 22:10 
AnswerRe: How to have more than one key and one value in any structure(like hash table) in C#? Pin
Mirko198030-Jul-09 22:14
Mirko198030-Jul-09 22:14 
QuestionGetting a program to open, search for a line of code, and edit it. Pin
craigchrist823930-Jul-09 20:32
craigchrist823930-Jul-09 20:32 
AnswerRe: Getting a program to open, search for a line of code, and edit it. Pin
dan!sh 30-Jul-09 21:00
professional dan!sh 30-Jul-09 21:00 
GeneralRe: Getting a program to open, search for a line of code, and edit it. Pin
craigchrist823930-Jul-09 21:12
craigchrist823930-Jul-09 21:12 
GeneralRe: Getting a program to open, search for a line of code, and edit it. Pin
dan!sh 30-Jul-09 21:21
professional dan!sh 30-Jul-09 21:21 
Questionhow to get the directory path when copy, past ( windows explorer) Pin
xinmoigocua30-Jul-09 19:57
xinmoigocua30-Jul-09 19:57 
AnswerRe: how to get the directory path when copy, past ( windows explorer) Pin
stancrm30-Jul-09 20:25
stancrm30-Jul-09 20:25 
QuestionChange BackColor in LISTBOX of any partincular item or index Pin
M Riaz Bashir30-Jul-09 19:47
M Riaz Bashir30-Jul-09 19:47 
AnswerRe: Change BackColor in LISTBOX of any partincular item or index Pin
dan!sh 30-Jul-09 20:34
professional dan!sh 30-Jul-09 20:34 
GeneralRe: Change BackColor in LISTBOX of any partincular item or index Pin
M Riaz Bashir30-Jul-09 21:15
M Riaz Bashir30-Jul-09 21:15 
QuestionHow to draw Graph using C# .Net Pin
nilam247730-Jul-09 18:40
nilam247730-Jul-09 18:40 
AnswerRe: How to draw Graph using C# .Net Pin
Christian Graus30-Jul-09 18:57
protectorChristian Graus30-Jul-09 18:57 

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.