Passing Parameter

Parameter is the variable listed inside the parentheses in the method definition. An argument is the actual value that is sent to the function when it is called. We can create a method with n number of Parameters inside. when a method is called, a new storage location is created for each parameters.

CODE

EG 1 . Creating a multiplication table method with table number and limit as Parameters.

static void Main() {
    //Assigning value of parameters(Arguments) while invoking.
    MultiplicationTable(17,20);
}
//Here table number and limit are the Parameters. Whenever this method invoked those 2 parameters value must be assigned.
static void MultiplicationTable(int tableNumber, int limit) {
    for (int i=1; i <= limit; i++) {
        Console.WriteLine(tableNumber+" * "+i+" = "+(tableNumber*i));
    }
}



EG 2 . Creating a method to print Right angle triangle shape using * and passing row value as parameter.

static void Main() {
    //Assigning value of row as 10 while invoking.
    PrintRightAngleTraingleShape(10);
}
//Here row is the Parameters. Whenever this method invoked row parameter value must be assigned.
static void PrintRightAngleTraingleShape(int row) {
    for (int i=1;i<=row;i++) {
        for (int j=1;j<=i;j++) {
        Console.Write("*");
        }
    Console.WriteLine();
    }
}




(Click Here, For more exercises)