How to create global variable
-
Hi all, In my application i have 5 forms. I would like to store some value in global varialble which can access by any forms in my app.I have try to create a get/set class and i declare a public object in form let said form A. But i can't access the object in form B. My example coding as below: Class GetSet:
private String _name; public String name { get{return _name;} set{_name = value;} }
FormA:public partial class FrmA : Form { GetSet gs; public FrmMain() { gs = new GetSet(); gs.name = "cocoon"; } }
FormB:public partial class FrmB : Form { GetSet gs; public FrmMain() { console.write(gs.name); } }
Can anyone guide me to slove this out. thanks in advance regards cocoon -
Hi all, In my application i have 5 forms. I would like to store some value in global varialble which can access by any forms in my app.I have try to create a get/set class and i declare a public object in form let said form A. But i can't access the object in form B. My example coding as below: Class GetSet:
private String _name; public String name { get{return _name;} set{_name = value;} }
FormA:public partial class FrmA : Form { GetSet gs; public FrmMain() { gs = new GetSet(); gs.name = "cocoon"; } }
FormB:public partial class FrmB : Form { GetSet gs; public FrmMain() { console.write(gs.name); } }
Can anyone guide me to slove this out. thanks in advance regards cocoonYou have to rethink your design.
cocoonwls wrote:
How to create global variable
You can't. However, you can create a static class which is quite similar to what you are asking for. There are plenty of examples on Google.
Cheers, Vikram.
The hands that help are holier than the lips that pray.
-
Hi all, In my application i have 5 forms. I would like to store some value in global varialble which can access by any forms in my app.I have try to create a get/set class and i declare a public object in form let said form A. But i can't access the object in form B. My example coding as below: Class GetSet:
private String _name; public String name { get{return _name;} set{_name = value;} }
FormA:public partial class FrmA : Form { GetSet gs; public FrmMain() { gs = new GetSet(); gs.name = "cocoon"; } }
FormB:public partial class FrmB : Form { GetSet gs; public FrmMain() { console.write(gs.name); } }
Can anyone guide me to slove this out. thanks in advance regards cocoonThe way to do this, is to use delegates, or create a class with static properties. If you thought that FrmB would do anything but crash, or had any chance of seeing hte value 'cocoon', you need to do some serious reading on OO, because you've misunderstood quite a bit.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
Hi all, In my application i have 5 forms. I would like to store some value in global varialble which can access by any forms in my app.I have try to create a get/set class and i declare a public object in form let said form A. But i can't access the object in form B. My example coding as below: Class GetSet:
private String _name; public String name { get{return _name;} set{_name = value;} }
FormA:public partial class FrmA : Form { GetSet gs; public FrmMain() { gs = new GetSet(); gs.name = "cocoon"; } }
FormB:public partial class FrmB : Form { GetSet gs; public FrmMain() { console.write(gs.name); } }
Can anyone guide me to slove this out. thanks in advance regards cocoonHi Vikram and Christian, Thanks for your reply. I have read through the static class and it useful to me. Then, Christian Graus, can you please explan a bit more to me why would you said i am misunderstood OO concept? Thanks in advance. ;) regards cocoon
-
Hi all, In my application i have 5 forms. I would like to store some value in global varialble which can access by any forms in my app.I have try to create a get/set class and i declare a public object in form let said form A. But i can't access the object in form B. My example coding as below: Class GetSet:
private String _name; public String name { get{return _name;} set{_name = value;} }
FormA:public partial class FrmA : Form { GetSet gs; public FrmMain() { gs = new GetSet(); gs.name = "cocoon"; } }
FormB:public partial class FrmB : Form { GetSet gs; public FrmMain() { console.write(gs.name); } }
Can anyone guide me to slove this out. thanks in advance regards cocoonYou can use singleton class object. It will help in state maintainance in the application.
Sarvesh Upadhyay Senior Software Engineer Birlasoft India Ltd. Microsoft Certified Professional Developer in Dotnet 2.0 Enterprise Application