In your main function you are printing what the function returns, after you call it:
ret = n.FindMax(a, b); //calls function with params a and b
Console.WriteLine("Max value is : {0}", ret ); //prints out the value returned by FindMax
So, to make your function print out the result, just print out the result inside the function, instead of returning it. Replace the return result;
in FindMax
with Console.WriteLine("Max value is : {0}", result );
, since you want to print result
instead of returning it.
Now in your Main
function instead of setting ret
to the return of FindMax
, and printing it out, just call n.FindMax(a, b);
, and it will print the result.
Also, you have to change public int FindMax(int num1, int num2)
to public void FindMax(int num1, int. num2)
, since it doesn’t return anything (see the doc page for more info on void).
I highly recommend that you just leave it how it is, but this is how you do it. (I’m not sure if you still want to return the value, I interpreted that you just want to print it out when the function is called
2
solved Printing output by inside method