Methods - Basics

  • A method (AKA function) is a reusable block of code.

  • Can (optionally) pass values in and get values back (also optional).

    • You almost always do want to do both those things.

Methods with no parameters and no return type

static void Main(string[] args)
{
    // Calling the function
    BasicFunction();
}

// Function
static void BasicFunction()
{
    Console.WriteLine("This is a function.");
}

Methods that return a value

Methods that take in parameters

Methods with parameters and a return type

Last updated