+ 3

How can I do a variable that can be use un all forms? (C#)

For example: Supposed to have 2 forms, We have Form A and Form B. In Form A I do a variable called "pancake". And I want to call that variable in Form B, how can I do that?

6th Mar 2018, 12:12 AM
SebGM2018
SebGM2018 - avatar
4 Respuestas
+ 12
in form a: class A { private int n; public int getN() { return n; } } in form b: A a = new A(); int b = a.getN();
6th Mar 2018, 12:53 AM
Vukan
Vukan - avatar
+ 10
by using object-oriented programming in way: create object in form b of form a, in form a write get method for that variable which will return variable value and call that method in form b with object which did you create
6th Mar 2018, 12:35 AM
Vukan
Vukan - avatar
+ 2
Can you give me a Code example?
6th Mar 2018, 12:42 AM
SebGM2018
SebGM2018 - avatar
+ 2
Thanks!
6th Mar 2018, 12:55 AM
SebGM2018
SebGM2018 - avatar