I have a very simple program actually want to grab the concept; for methods with non-void return type as in my case its int, I am obliged to use a return statement but using that return statement am unable to print a number that I have taken from the user. What I need to do? Thanks
I can use the Console.WriteLine() method in this if-else to let the user know that his/her entered number is even or not But this return statement is then for which purpose?
namespace x { class CheckEvenNum { static int Check(int num) { if (num % 2 == 0) { Console.WriteLine("It is a even number"); return num; // Want to print the number on console with this return } else { Console.WriteLine("Not an even number"); return -1; // Want to print the number on console with this return } } static void Main(string[] args) { Console.WriteLine("Enter a positive number"); int number=Convert.ToInt32(Console.ReadLine()); CheckEvenNum.Check(number); } } }