⚙️ Lesson: C# Functions & Methods

Functions (or methods) in C# are blocks of reusable code that perform specific tasks. They help organize your code, avoid repetition, and make programs easier to read and maintain.

Function Syntax

returnType FunctionName(parameters) {
    // function body
    return value;
}

Explanation:

Example: Adding Two Numbers

int AddNumbers(int a, int b) {
    return a + b;
}

This function takes two integers and returns their sum.

Try It Yourself: Call AddNumbers

Result will appear here...

Quiz: Test Your Knowledge on C# Functions

1. What is the purpose of a function in C#?

2. What keyword defines a function that does not return any value?

3. Which is the correct way to call AddNumbers(5, 10)?

4. How do you specify a function’s return type in C#?

5. What does this function do?
int MultiplyNumbers(int a, int b) { return a * b; }