Files
CSharp-learning/C# Full Course for free/13.methods.md
2026-01-13 03:16:55 +01:00

1.3 KiB

Methods

singHappyBirthday();

static void singHappyBirthday(){

Console.WriteLine("Happy birthday to you")
}

arguments

String name = "mrsh"
int age = 30;

singHappyBirthday(name, age);

static void singHappyBirthday(String namem int age){

Console.WriteLine("Happy birthday to you" + name)
Console.WriteLine("you are " + age + "years old")
}

return

double x = 5.3;
double y = 3;

double result = Multiply(x,y)

static double Multiply(double x, double y){
    double z = x * y;
    return z;
}

method overloading

double x = 5.3;
double y = 3;
double z = 3;

double result = Multiply(x,y)
// Will return the first Multiply method
double result = Multiply(x,y,z)
// Will return the second Multiply method

static double Multiply(double x, double y){
    double z = x * y;
    return z;
}

static double Multiply(double a, double b, double c){
    double z = x * y;
    return z;
}

params

params keyword a method parameter that takes a variale number of arguments. the parameter type must be a single - dimensional array


double total = CheckOut(3.99, 5,75, 15);

static double Checkout(params double[] prices){

    double total =0;
    foreach(double price in prices)
    {
        total += prices;
    }

return total;
}