c# - Form instance members and static member -
i have formdlg can accessed 2 two forms button click on form1, needs instance- can have multiple formdlg
but other place, need single instance of formdlg
any ideas thank u
following example code of class can provide answer you.
class formdlg { static formdlg instance; public static formdlg getinstance() { if (instance == null) instance = new formdlg(); return instance; } }
since constructor public can call new in form1 multiple instances anytime want.
in form2 use static function getinstance retreive single instance everytime.
hope helps.
Comments
Post a Comment