0
How to call Int in a new Method
Here's my code: namespace SoloLearn { class Program { static void Main(string[] args) { int num; num = Convert.ToInt32(Console.ReadLine()); PrintRounds(); } static void PrintRounds() { int y; y = num; if(y % 2 == 0) { Console.WriteLine("Even"); } else { Console.WriteLine("Odd"); } } } } When calling Int Num in Method PrintRounds, I get an error saying that num is not available. Even when I try making int num public in Main Method, it still doesnt work. Why is this and how can it be fixed?
1 Odpowiedź
0
Scope probleme.
num is only available in main function scope.
try to move the declaration outside the main function.
just after the class Program {
would be a good place for it.
Hope this helps