+ 3
How to create a variable that works in all WinForms? (C#)
I need a variable that I can call no matter in which Form I am writing. Do I need to use a class, a static or an object? Because I tried to use the class and static and I only can call it once in one form
2 Respostas
+ 6
make variable public in some class and then you can take value of that variable by creating object for that class and call method that return you value of that variable
+ 1
You can add a class to your project and make the class static
static class TheGlobalClass
{
public static GlobalVariable1 {get; set}
}
I would recommend not to do it. It is bad practice. If a variable is not anywhere it can be changed anywhere. This can cause unexpected behaviour.
If you need to now about a variable in a form, make a property and assign the value to this propertie.