I’ve done some research on global variables, and have come up with the fact that static variables should be able to solve my problem. I don’t understand how to make these, though. How would I do so? Also, if static variables would not solve my problem, what should I use?
I want to be able to access a string, bool and int in my main form, from another form. Help?
Static variables (or better yet, properties) would likely work. You would declare this as:
And then, to access, you’d use
Form1.SomeBool = true;orif (Form1.SomeBool) {, etc.That being said, “global” data like this is discouraged for a reason – there is typically some better way to handle this. For example, you might want to make a custom class that holds your data, and pass a reference to an instance of this class to the new form when you create it.