In C #, The Destructor are called by the garbage collector. When the referenced data on the stack is invalid, it is called implicitly. Generally, it is called when the referenced variable is out of its scope.
The close and dispose functions are a convention:
After the close function is called to release resources, it may need to be used again, but the resources released by the dispose function are no longer used;
In addition, if the class implements the idisposable interface and you can use the Using Keyword when instantiating the class, the dispose function is called implicitly when it exceeds the scope of the using keyword,
For example:
Using (ctest inst = new ctest ()) Itpub personal space f1o) u3bc) E
{
// Do something;
} // Call dispose method here
Differences:
1. Add a MessageBox in the protected override void dispose (bool disposing) method, and then add a button in the form.CodeIs this. Close ();
Messabebox will not pop up, that is, the dispose method will not be called;
Change the button Event code to: This. Dispose ();Itpub personal space "} 4yns-y6pw! HD | S
MessageBox will pop up, that is, directly destroy all resources opened by the form.
3fj! C ^ lcx0
2. Use
Form. frm2 = new form2 ();Itpub personal space C' "y6k $ J _
Frm2.showdialog ();
After you use the close () method in form2 to close the form form2, you can still directly use frm2.showdialog () in form1 to display the form2.
Wwy7iyp % Q % @ 0
After the form form2 is closed using the dispose () method, you cannot directly use frm2.showdialog () in form1 to display form2. You still need to create a new instance form. frm2 = new form2 ();
ArticleSource: http://space.itpub.net/12639172/viewspace-580649