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

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -