+ 9
How to create a variable and use it anywhere in the code? ( C# WFA )
I am working in a c# code in windows form application and I need a variable I can use anywhere. Where or how do I need to write it?
2 ответов
+ 6
Create a file for variable declaration and include that file where you want. But variable will be Global. So you may get lots of problem. That's why we have Global and Local variable.
But according to this link c# doesn't support global variable directly.
https://www.arclab.com/en/kb/csharp/global-variables-fields-functions-static-class.html
+ 2
If you want this variable to be the same variable used everywhere and all parts of your code to see the same value for this variable , meaning a single instance of this variable then create a public static class with a public static variable. You can then use the class name.variable name to access it.