I have a dialog box (form) that configures items in a class. I'm
wanting make sure that I handle OK and Cancel properly and that I also
manage memory (I hate the fact the C# supposedly does this for me).
Nonetheless, my question is regarding cloning. I'm assuming that I
have to clone my object into the dialog so that I can corrupt it in
the dialog and still hit "Cancel". Do I then need to clone it back
into the calling object when the user hits "OK" or can I just do a
"copy" (with the "=" operator)?
public class MyBaseClass
{
MySettingsClass myClassToConfigure ;
void CallADialog ()
{
DialogForm dlg = new DialogForm();
dlg.theClass =
(MySettingsClass)myClassToConfigure.Clone() ; // make a copy for the
dialog
if (dlg.ShowDialog() == DialogResult.OK)
{
myClassToConfigure = dlg.theClass ; // or should
I "Clone" it back?
}
} // end CallADialog
} // end MyBaseClass