How can i take int from one method to another method? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How can i take int from one method to another method?

so i am trying to make base convertor, and i need to take an intger from one method to another, how can i do it? for example i have x =5 in method Main and i need to use that x in another method, how can i do it?

3rd Apr 2017, 10:08 AM
Benji Bogozini
Benji Bogozini - avatar
2 Answers
+ 19
ref/out ref tells the compiler that the object is initialized before entering the function, while out tells the compiler that the object will be initialized inside the function. So while ref is two-ways, out is out-only. https://code.sololearn.com/c11GKcrPtFLq/?ref=app
3rd Apr 2017, 1:58 PM
Illusive Man
Illusive Man - avatar
+ 1
for beginners using global variable or property. using pointer like out key could cause you an error if not used properly. property will be consistent​ all over class in class level declare the variable. class myproject{ public static int _myvar { get; set;} static int main() { myvar = 5; } public method2(){ int newint = myvar; print(newint) } } output : 5 <<<<<
3rd Apr 2017, 9:28 PM
milk way
milk way - avatar