0
Method Question
I donât know how to have a Method Output... Can you give me an exemple plz? using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { { int x = 4; int y = x; } int Multiplication(int x, int y) { return x*y; } } } }
1 Answer
+ 1
Do you mean how to obtain a method's return value? if that's the case then you prepare a variable to hold the output, it must be of the same type declared in function definition.
Because in your code `Multiplication` returns an `int`, so you need to declare an int also. You then assign the return value to the variable, as follows:
int z = Multiplication(x, y);
Console.WriteLine("{0} * {1} = {2}", x, y, z);
Never mind if it wasn't what you asked for.