0
Can someone explain to me passing arguments in C#?
i did the exercises but i didn't understand them very well how they worked
1 Resposta
+ 1
When you 'pass' arguments you just give the function something to work with. For example you may write:
int multiplyMe(int num1,int num2){
return num1*num2;
}
In this function you give it two ints and it returns an int. The two args are just values that you pass in:
multiplyMe(5,2);
//Returns 10
multiplyMe(3,8);
//Returns 24
You can pass variables:
int x = 3;
int y = 6;
multiplyMe(x,y);
//Returns 18
You can assign the return to a variable:
int x;
x = multiplyMe(3,2);
//x equals 6
Hopefully these examples help you understand.