+ 1
I wish someone can be holding a private classes with me,methods in c# is getting abit tough for me.
Need serious help.
6 ответов
+ 1
1) You can send multiple parameters to a function
For example if you want to create a function that makes the sum of two numbers you need to pass two arguments to a function that accepts two parameters, make the sum of them and return the value.
2) Optional parameters are parameters that aren't necessary for the function
For example your sum function can make the sum of two or three numbers depending on of how many arguments you pass to it
the third parameter has to have a default value, in this case 0 so that when you pass only two values it doesn't change the result
3) You can use named arguments when you don't remember the order of the parameters
you specify the parameter name inside the call of the function
Tell me if you need examples
+ 1
What's your problem?
+ 1
yes. I need examples
+ 1
1) int arg1 = 3;
int arg2 = 2;
int argSum;
int sum(int param1, int param2)
{
argSum = param1 + param2;
Console.WriteLine(argSum.ToString());
}
sum(arg1, arg2);
2) int arg1 = 3;
int arg2 = 2;
int arg3 = 4;
int argSum;
int sum(int param1, int param2, int param3 = 0)
{
argSum = param1 + param2 + param3;
Console.WriteLine(argSum.ToString());
}
sum(arg1, arg2);
sum(arg1, arg2, arg3);
3) int arg1 = 3;
int arg2 = 2;
int argSum;
int sum(int param1, int param2)
{
argSum = param1 + param2;
Console.WriteLine(argSum.ToString());
}
sum(param2: arg2, param1: arg1);
+ 1
wow. thanks a lot.
0
multiple parameters, optional and named arguments