diff --git a/10-static-members-methods-and-classes.md b/10-static-members-methods-and-classes.md
index a5c96dd..cbe3fd9 100644
--- a/10-static-members-methods-and-classes.md
+++ b/10-static-members-methods-and-classes.md
@@ -11,7 +11,7 @@ title: 10. Static Members, Methods and Classes
-## Static Members
+## Static members
### Non-static members
@@ -140,7 +140,7 @@ class Program
## Static methods
-* Methods can also be static
+* Methods can also be static — for example, `Console.WriteLine`
* What happens when you try to call a non-static method from a static method?
```csharp
class Program
diff --git a/6-methods-slides.html b/6-methods-slides.html
new file mode 100644
index 0000000..cd5b94c
--- /dev/null
+++ b/6-methods-slides.html
@@ -0,0 +1,361 @@
+6. Methods
+
Methods
+
+
+
Overview
+
+
Functions
+
Methods
+
Parameters
+
Return values
+
Scope of methods
+
+
+
+
What is a function?
+
+
Functions are self-contained modules of code that accomplish a specific task
+
Basically, a named block of code that can be executed as many times as we want
+
+
Instead of writing the same code over and over again, do it only once as a function, and call it many times
+
+
voidExample()
+{
+ Console.WriteLine("Hello World");
+}
+
+Example(); // calling the function three times
+Example();
+Example();
+
+
+
+
+
+
Parameters and returns
+
+
Functions can acquire data, a.k.a. parameters, from the caller
+
Functions can return data, a.k.a. its return value, to the caller
+
Defining parameters and return values are optional — not all functions have both, and some have neither!
+
Here's a function that takes in one parameter and returns nothing (hence, void)
voidPrintName(string param)
+{
+ Console.WriteLine("My name is " + param);
+}
+
+
+
+
+
+
Function execution
+
When a function is called, the program leaves the current section of the code and begins to execute the first line of code inside the function.
+
+
The program execution comes to the line of code where the function call is
+
The program enters the function
+
Instructions inside the function are executed from top to bottom
+
+
+
Remember scopes: The variables defined inside the function are not visible outside the function!
+
+
+
The program leaves the function and returns to the point where the function call was and continues the execution
+
If the function returned any data, it can be used where the function was called
+
+
+
+
Methods vs functions
+
+
In C#, most functions we see are methods: functions that are inside a class
+
Even the main function is inside a class in C#, so it is a method
+
Note: If only one value from a tuple is needed, you can use a discard (_)
// Only the last name is allocated to a variable
+(_, string lastName) = FirstAndLastName("Arnold Alois Schwarzenegger");
+
+
+
+
+
+
Scope of methods
+
+
+
The variables declared inside a method are local variables and only accessible inside the method
+
voidScopeExample()
+{
+ // Variable 'a' is only accessible inside of this method
+ int a = 10;
+ a = 20; // This works
+}
+a = 30; // This throws an error
+
+
+
+
Contrastingly, variables declared outside the method are available inside, as seen in an earlier example
+
+
+
+
+
Exercise 2
+
+
+
Write a method that takes a string as a parameter and prints the total number of spaces in that string.
+
Without using the string.Trim() method, modify the method so that it removes the spaces in a string and returns a new string.
+
+
Hint: You can iterate a string just like arrays and lists.
+
+
+
+
Exercise 3
+
+
+
+
Write a method that takes in a string as a parameter and prints each unique letter in that string.
+
Write a new method that takes a string as a parameter and prints the number of each unique letter in the string.
+
+
+
+
+
+
+
+
+
Exercise 4
+
+
+
Write a method that takes in a 10-digit number as a parameter and divides individual digits into two arrays of even and odd digits. The method should return both arrays.
+
Remember to check that method only accepts numbers!
+
+
+
+
Exercise 5
+
+
+
Fix this example that utilized a bad practice where a variable declared outside the function is modified inside the function.
+
So instead, take in the centuriesPrinted variable as another parameter, modify it in the function, and then return it.
\ No newline at end of file
diff --git a/6-methods.md b/6-methods.md
index 2a8edad..34ff709 100644
--- a/6-methods.md
+++ b/6-methods.md
@@ -1,270 +1,320 @@
-# Methods
-
-
-
---
-
-# Overview
-
-Functions
-
-Methods
-
-Parameters
-
-Return Values
-
-Scope of Methods
-
-# What is a function?
-
-* Functions are self contained modules of code that accomplish a specific task.
-* Function is basically a block of code that can be executed over and over again in the program
- * Instead of writing the same code over and over again to the program, it can be written only once as a function
-* Functions can get data, _parameters_ , from the _caller_
-* Functions can return data, _return value_ , to the caller
-* Defining parameters and return values are optional, not all functions have both and some have neither!
-
-# Function execution
-
-* When a function is called the program leaves the current section of the code and begins to execute the first line of code inside the function.
-* The program execution comes to the line of code where the function call is
-* The program enters the function
-* Instructions inside the function are executed from top to bottom
- * Remember scopes: The variables defined inside the function are not visible outside the function!
-* The program leaves the function and returns to the point where the function call was and continues the execution
-* If function returned any data, it can be used where the function was called
+marp: true
+paginate: true
+math: mathjax
+theme: buutti
+title: 6. Methods
+---
# Methods
-In C#, __methods __ are functions which are inside of a class
-
-Since the main function is inside of a class, all functions in C# are actually just called methods
-
-* A methods are executed only when it is __called__
-* For example, Console.WriteLine() is a method which contains more complex code to print stuff on to the console
- * Instead of writing all that complex stuff at every printout, you can just use the short method call Console.WriteLine()
+
+
+
+## Overview
+
+* Functions
+* Methods
+* Parameters
+* Return values
+* Scope of methods
+
+## What is a function?
+
+* Functions are self-contained modules of code that accomplish a specific task
+* Basically, a named block of code that can be executed as many times as we want
+ * Instead of writing the same code over and over again, do it only once as a function, and ***call*** it many times
+ ```csharp
+ void Example()
+ {
+ Console.WriteLine("Hello World");
+ }
+
+ Example(); // calling the function three times
+ Example();
+ Example();
+ ```
+
+### Parameters and returns
+
+* Functions can acquire data, a.k.a. **_parameters_**, from the **_caller_**
+* Functions can return data, a.k.a. its **_return value_**, to the caller
+* Defining parameters and return values are optional — not all functions have both, and some have neither!
+* Here's a function that takes in one parameter and returns nothing (hence, `void`)
+ ```csharp
+ void PrintName(string param)
+ {
+ Console.WriteLine("My name is " + param);
+ }
+ ```
+
+## Function execution
+
+When a function is called, the program leaves the current section of the code and begins to execute the first line of code inside the function.
+1) The program execution comes to the line of code where the function call is
+2) The program enters the function
+3) Instructions inside the function are executed from top to bottom
+ * Remember scopes: The variables defined inside the function are not visible outside the function!
+4) The program leaves the function and returns to the point where the function call was and continues the execution
+5) If the function returned any data, it can be used where the function was called
+
+### Methods vs functions
+
+* In C#, most functions we see are *__methods__*: functions that are inside a ***class***
+* Even the main function is inside a class in C#, so it is a method
+ * Classes are explained in [Lecture 7](7-classes-and-objects)
+* Here's the earlier function as a method inside the `Program` class
+ ```csharp
+ class Program
+ {
+ void PrintName(string param)
+ {
+ Console.WriteLine("My name is " + param);
+ }
+ }
+ ```
+
+
+### Calling methods
+
+* A method is executed only when it is *__called__*
+* Some methods are already predefined, so we can call them right away
+* For example, `Console.WriteLine()` is a method that contains code that prints stuff in the console
+ * Instead of writing ourselves all that complex stuff the method contains, we just use the short method call `Console.WriteLine()`
* The use of methods reduces repetitive code, adds modularity and makes designing your programs easier
-# Methods - Example
+### Methods: An example
-
+
+
+```csharp
class Program
-
-{
-
-static void Main(string[] args)
-
-{
-
-void PrintBlock()
-
-{
-
-Console.WriteLine("---------------------");
-
-Console.WriteLine("| This is cool but |");
-
-Console.WriteLine("| you wouldn't want |");
-
-Console.WriteLine("| to write this |");
-
-Console.WriteLine("| block of code |");
-
-Console.WriteLine("| every time! |");
-
-Console.WriteLine("---------------------");
-
-}
-
-PrintBlock();
-
-PrintBlock();
-
-PrintBlock();
-
-}
-
-}
-
-* In this example, we declared a new method called PrintBlock
-* Finally the method was called three times
-* Each time the entire code inside the method was executed
-* The void statement means that the method does not return anything
- * More on that later
-
-# Parameters
-
-Sometimes you want to pass data into the method when calling it
-
-This is done by adding __parameters __ to the method declaration, inside the brackets:
-
-void PrintSum(int val1, int val2)
-
{
-
-int sum = val1 + val2;
-
-Console.WriteLine("Sum of " + val1 + " and " + val2 + " is " + sum);
-
+ void PrintBlock()
+ {
+ Console.WriteLine("---------------------");
+ Console.WriteLine("| This is cool but |");
+ Console.WriteLine("| you wouldn't want |");
+ Console.WriteLine("| to write this |");
+ Console.WriteLine("| block of code |");
+ Console.WriteLine("| every time! |");
+ Console.WriteLine("---------------------");
+ }
+
+ static void Main(string[] args)
+ {
+ PrintBlock();
+ PrintBlock();
+ PrintBlock();
+ }
}
+```
-The values to be passed are set as __arguments __ in the method call, inside the brackets:
+
+
-PrintSum(2, 5); // Outputs "Sum of 2 and 5 is 7
-
-PrintSum(5, 5); // Outputs "Sum of 5 and 5 is 10
+
-# Parameters - Example
+
+
-
+---
+* In the previous example, we declared a new method called `PrintBlock`
+* Then, the method was called three times
+ * Each time the entire code inside the method was executed
+* Why didn't we have to use the class name the method belonged to, unlike with `Console.WriteLine`?
+ * Short answer: Because we called the method inside the class
+* The `void` statement means that the method does not return anything
+ * More on that later!
+
+## Parameters
+
+* Sometimes you want to pass data into the method when calling it
+* This is done by adding *__parameters__* to the method declaration inside the parentheses:
+ ```csharp
+ void PrintSum(int val1, int val2)
+ {
+ int sum = val1 + val2;
+ Console.WriteLine("Sum of " + val1 + " and " + val2 + " is " + sum);
+ }
+ ```
+* The values to be passed are set as ***arguments*** in the method call inside the parentheses:
+ ```csharp
+ PrintSum(2, 5); // Outputs "Sum of 2 and 5 is 7
+ PrintSum(5, 5); // Outputs "Sum of 5 and 5 is 10
+ ```
+
+### Parameters: An example
+
+
+
+
+```csharp
static void Main(string[] args)
-
-{
-
-int centuriesPrinted = 0;
-
-void PrintCentury(int century)
-
-{
-
-centuriesPrinted++;
-
-Console.WriteLine("Current century: " + century);
-
-Console.WriteLine("Total centuries printed: " + centuriesPrinted);
-
-}
-
-for (int i = 0; i < 500; i += 100)
-
-{
-
-PrintCentury(i);
-
-}
-
-}
-
-# Optional Parameters
-
-You can give a parameter a default value by assigning it in the method declaration
-
-This makes the parameter optional
-
-double CircleArea(double radius = 0)
-
-{
-
-double area = Math.PI * radius * radius;
-
-return area;
-
-}
-
-Console.WriteLine(CircleArea()); // This outputs 0
-
-Console.WriteLine(CircleArea(2)); // This outputs 12,56637...
-
-# Exercise 1
-
-Write two methods Sum and Difference, which both have two parameters of type int, named value1 and value2. Sum should print "The sum of __*value1*__ and __*value2*__ is __*sum*__ ", and Difference should print "The difference of __*value1*__ and __*value2*__ is __*difference*__ .
-
-Call the methods from the main method multiple times with different values.
-
-# Return Values
-
-The return value of a method is __returned __ with the return keyword:
-
-double radius = 2;
-
-Console.WriteLine(CircleArea(radius)); // Outputs 12,56637...
-
-double CircleArea(double radius)
-
-{
-
-double area = Math.PI * radius * radius;
-
-return area;
-
-}
-
-In the first examples, the method declarations started with the void expression, which means that the method doesn't return anything
-
-Here the method was declared as type double, which means that the method has to return a variable of type double
-
-# Multiple Return Values
-
-It is possible to return multiple values in the form of a __tuple__ :
-
-(string, string) FirstAndLastName(string fullname)
-
{
-
-string[] names = fullname.Split(' ');
-
-return (names[0], names[names.Length - 1]);
-
+ int centuriesPrinted = 0;
+
+ void PrintCentury(int century)
+ {
+ centuriesPrinted++;
+ Console.WriteLine
+ ("Current century: " + century);
+ Console.WriteLine
+ ("Total centuries printed: " + centuriesPrinted);
+ }
+
+ for (int i = 0; i < 500; i += 100)
+ {
+ PrintCentury(i);
+ }
}
+```
-(string first, string last) = FirstAndLastName("Hans \\"Dolph\\" Lundgren");
-
-Console.WriteLine($"First name: {first}, last name: {last}");
-
-// Outputs "First name: Hans, last name: Lundgren"
+
+
-If only one value from a tuple is needed, you can use a __discard __ (\_)
-
-// Only last name is allocated to a variable
-
-(\_, string lastName) = FirstAndLastName("Arnold Alois Schwarzenegger");
-
-# Scope of Methods
-
-The variables declared inside of a method are __local variables__ and only accessible inside of that method
+
-void ScopeExample()
+Note that this method modifies a value that is ***outside*** the method, which is considered bad practice.
+
+
+
+
+## Optional parameters
+
+* You can give a parameter a default value by assigning it in the method declaration
+* This makes the parameter optional
+ ```csharp
+ double CircleArea(double radius = 0)
+ {
+ double area = Math.PI * radius * radius;
+ return area;
+ }
+ Console.WriteLine(CircleArea()); // This outputs 0
+ Console.WriteLine(CircleArea(2)); // This outputs 12,56637...
+ ```
+
+## Exercise 1
+
+
+1) Write two methods `Sum` and `Difference` that both take in two parameters of type `int`, `value1` and `value2`.
+ * `Sum` should print `The sum of and is `
+ * `Difference` should print `The difference of and is `
+2) Call the methods from the main method multiple times with different arguments.
+
+## Return Values
+
+* The return value of a method is *__returned__* with the `return` keyword:
+ ```csharp
+ double CircleArea(double radius)
+ {
+ double area = Math.PI * radius * radius;
+ return area;
+ }
+
+ double radius = 2;
+ double result = CircleArea(radius);
+ Console.WriteLine(result); // Outputs 12,56637...
+ ```
+* In the first examples, the method declarations started with the `void` keyword, which means that the method doesn't return anything
+* Here the method was declared as type `double` — now the method ***must*** return a `double` type variable
-{
+### Note about shortening
-// Variable 'a' is only accessible inside of this method
+* The earlier code
+ ```csharp
+ double radius = 2;
+ double result = CircleArea(radius);
+ Console.WriteLine(result);
+ ```
+* can be shortened to
+ ```csharp
+ double result = CircleArea(2);
+ Console.WriteLine(result);
+ ```
+* and even further into
+ ```csharp
+ Console.WriteLine(CircleArea(2));
+ ```
-int a = 10;
+## Using tuples for multiple return values
-a = 20; // This works
+* It is possible to return multiple values in the form of a *__tuple__*:
+ ```csharp
-}
+ (string, string) FirstAndLastName(string fullname)
+ {
+ string[] names = fullname.Split(' ');
+ return (names[0], names[names.Length - 1]);
+ }
-a = 30; // This throws an error
+ (string first, string last) = FirstAndLastName("Hans \"Dolph\" Lundgren");
-# Exercise 2
+ Console.WriteLine($"First name: {first}, last name: {last}");
+ // Outputs "First name: Hans, last name: Lundgren"
+ ```
+* ***Note:*** If only one value from a tuple is needed, you can use a *__discard__* (`_`)
+ ```csharp
+ // Only the last name is allocated to a variable
+ (_, string lastName) = FirstAndLastName("Arnold Alois Schwarzenegger");
+ ```
-Write a method that takes a string as a parameter and prints the total number of spaces in that string.
+## Scope of methods
-Without using the string.Trim() method, modify the method so that it removes the spaces in a string and returns the new string.
+* The variables declared inside a method are *__local variables__* and only accessible inside the method
+ ```csharp
+ void ScopeExample()
+ {
+ // Variable 'a' is only accessible inside of this method
+ int a = 10;
+ a = 20; // This works
+ }
+ a = 30; // This throws an error
+ ```
-(Hint: You can iterate a string just like arrays and lists.)
+* Contrastingly, variables declared outside the method are available inside, as seen in an earlier [example](#parameters-an-example)
-
+## Exercise 2
+
+
+1) Write a method that takes a string as a parameter and prints the total number of spaces in that string.
+2) Without using the `string.Trim()` method, modify the method so that it removes the spaces in a string and returns a new string.
+
+***Hint:*** You can iterate a string just like arrays and lists.
+
+
+
+## Exercise 3
+
+
+
+
-# Exercise 3
+1) Write a method that takes in a string as a parameter and prints each unique letter in that string.
+2) Write a new method that takes a string as a parameter and prints the number of each unique letter in the string.
-Write a method that takes a string as a parameter and prints each unique letter in that string.
+
+
-Write a new method that takes a string as a parameter and prints the number of each unique letter in the string.
+
-
+
+
-# Exercise 4
+## Exercise 4
+
-Write a method that takes a 10 digit number as a parameter and divides individual digits into even and odd arrays. Method should return both arrays.
+* Write a method that takes in a 10-digit number as a parameter and divides individual digits into two arrays of even and odd digits. The method should return both arrays.
+* Remember to check that method only accepts numbers!
-Remember to check that method accepts only numbers.
+## Exercise 5
+
-# Assignments
+* Fix this [example](#parameters-an-example) that utilized a bad practice where a variable declared outside the function is modified inside the function.
+* So instead, take in the `centuriesPrinted` variable as another parameter, modify it in the function, and then return it.
-[Assignments about this topic can be found here](https://gitea.buutti.com/education/academy-assignments/src/branch/master/C%23%20Basics/6.%20Methods)
+## Assignments
+[Assignments about this topic can be found here](https://gitea.buutti.com/education/academy-assignments/src/branch/master/C%23%20Basics/6.%20Methods)
\ No newline at end of file