3
In my application you will have a login system. I want to create a variable to store the user id that is logged in, and that it can be accessed in all other forms.
I need this because in my database, each table has a field called usuario
which will store the name of the user who saved the record in the database.
Whenever I want to use the variable in another form, I do so:
form meuLogin = new form();
meuLogin.idUsuario = tabela.id;
So I always create a new object from formLogin
(which is where the variable idUsuario
is stored) to be able to pick up the variable. I’m doing it right or has a way to make a variable "global"?
Turn her into static maybe?
public static string exemplo { get; set;}
. As long as there is no competition for this variable I believe that everything will be fine. I just don’t know if this is the best way to do it.– Christian Beregula
You should not create global variables. You can do what the above comment says, but you may have problems in concurrent environments. http://answall.com/q/21158/101. The question lacks more context to offer a suitable solution, or at least to say where to create this static variable. But if I get it, it’s not right at all.
– Maniero
changed the question
– Italo Rodrigo