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; } } } }

10th Feb 2019, 12:21 AM
Mathieu
1 Resposta
+ 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.
10th Feb 2019, 2:42 AM
Ipang