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?
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
+ 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 <<<<<