|
14 | 14 | " Previously in Session 2, we wrote constructors to allow you to control the creation of classes. These are _methods_ but this time we will expand on what we've previously learned\n",
|
15 | 15 | "</div>\n",
|
16 | 16 | "\n",
|
17 |
| - "[Methods are defined in the official documentation](https://docs.microsoft.com/dotnet/csharp/programming-guide/classes-and-structs/methods) as a code block containing a series of statements that the program can execute. We're going to expand on that definition to also state that a method can (but is not required) return values to its caller. We typically think of methods as an action that our class _performs_ or an _acting on_ the class.\n", |
| 17 | + "[Methods are defined in the official documentation](https://docs.microsoft.com/dotnet/csharp/programming-guide/classes-and-structs/methods?WT.mc_id=visualstudio-twitch-jefritz) as a code block containing a series of statements that the program can execute. We're going to expand on that definition to also state that a method can (but is not required) return values to its caller. We typically think of methods as an action that our class _performs_ or an _acting on_ the class.\n", |
18 | 18 | "\n",
|
19 | 19 | "A method has a **signature** that defines how you can interact with it. The signature is followed immediately by curly braces **{ }** that wrap the code to be executed in the method and takes the following format:\n",
|
20 | 20 | "\n",
|
|
725 | 725 | "source": [
|
726 | 726 | "## Delegates\n",
|
727 | 727 | "\n",
|
728 |
| - "Now that we know what a method is and how to interact with them, sometimes we want to pass a pointer to that method around our program. This pointer to the method is called a **Delegate** and allows us to call the method from another ___location. Delegates are defined with the method signature that they need to match in order to reference that method. The [official documentation on delegates](https://docs.microsoft.com/dotnet/csharp/programming-guide/delegates/) has more on defining a delegate.\n", |
| 728 | + "Now that we know what a method is and how to interact with them, sometimes we want to pass a pointer to that method around our program. This pointer to the method is called a **Delegate** and allows us to call the method from another ___location. Delegates are defined with the method signature that they need to match in order to reference that method. The [official documentation on delegates](https://docs.microsoft.com/dotnet/csharp/programming-guide/delegates?WT.mc_id=visualstudio-twitch-jefritz) has more on defining a delegate.\n", |
729 | 729 | "\n",
|
730 | 730 | "Delegates are sometimes referred to as **Callback Functions**\n",
|
731 | 731 | "\n",
|
|
846 | 846 | "source": [
|
847 | 847 | "### Multicast delegates\n",
|
848 | 848 | "\n",
|
849 |
| - "Defined delegate types can be [**multicast**](https://docs.microsoft.com/dotnet/csharp/programming-guide/delegates/how-to-combine-delegates-multicast-delegates) allowing them to point to multiple methods to be called. This sounds a LITTLE weird, but it means that we can stack executions and pass that entire stack into another method. Let's take a look at that `Student` and `CalculateHandler` from our previous example again." |
| 849 | + "Defined delegate types can be [**multicast**](https://docs.microsoft.com/dotnet/csharp/programming-guide/delegates/how-to-combine-delegates-multicast-delegates?WT.mc_id=visualstudio-twitch-jefritz) allowing them to point to multiple methods to be called. This sounds a LITTLE weird, but it means that we can stack executions and pass that entire stack into another method. Let's take a look at that `Student` and `CalculateHandler` from our previous example again." |
850 | 850 | ]
|
851 | 851 | },
|
852 | 852 | {
|
|
984 | 984 | "source": [
|
985 | 985 | "## Events\n",
|
986 | 986 | "\n",
|
987 |
| - "[Events](https://docs.microsoft.com/dotnet/csharp/programming-guide/events/) allow us to notify when something has happened inside of our class. Events build on the concept of delegates as they reference another method that should be called when the event is **raised**. We define an event with access modifiers and by .NET standard practice, two arguments: \n", |
| 987 | + "[Events](https://docs.microsoft.com/dotnet/csharp/programming-guide/events?WT.mc_id=visualstudio-twitch-jefritz) allow us to notify when something has happened inside of our class. Events build on the concept of delegates as they reference another method that should be called when the event is **raised**. We define an event with access modifiers and by .NET standard practice, two arguments: \n", |
988 | 988 | "\n",
|
989 | 989 | "- the sender \n",
|
990 | 990 | "- a class that contains any arguments about the event being raised. \n",
|
|
1041 | 1041 | "source": [
|
1042 | 1042 | "### Generic EventHandler definition\n",
|
1043 | 1043 | "\n",
|
1044 |
| - "Insted of writing your own delegate for each event, [you can use a generic `EventHandler<T>`](https://docs.microsoft.com/dotnet/csharp/programming-guide/events/how-to-publish-events-that-conform-to-net-framework-guidelines#example) and specify the type of the `EventArgs` that you would like the Event to return." |
| 1044 | + "Insted of writing your own delegate for each event, [you can use a generic `EventHandler<T>`](https://docs.microsoft.com/dotnet/csharp/programming-guide/events/how-to-publish-events-that-conform-to-net-framework-guidelines?WT.mc_id=visualstudio-twitch-jefritz#example) and specify the type of the `EventArgs` that you would like the Event to return." |
1045 | 1045 | ]
|
1046 | 1046 | },
|
1047 | 1047 | {
|
|
1086 | 1086 | "source": [
|
1087 | 1087 | "## Partial Keyword\n",
|
1088 | 1088 | "\n",
|
1089 |
| - "Classes can be defined across multiple files in separate class code blocks and then stitched together as a single class object. This type of file layout and class design helps facilitate generating a class from metadata and allowing customization of that class in a second or third file. You can use the [`partial` keyword to define each of the parts of the class](https://docs.microsoft.com/dotnet/csharp/programming-guide/classes-and-structs/partial-classes-and-methods).\n", |
| 1089 | + "Classes can be defined across multiple files in separate class code blocks and then stitched together as a single class object. This type of file layout and class design helps facilitate generating a class from metadata and allowing customization of that class in a second or third file. You can use the [`partial` keyword to define each of the parts of the class](https://docs.microsoft.com/dotnet/csharp/programming-guide/classes-and-structs/partial-classes-and-methods?WT.mc_id=visualstudio-twitch-jefritz).\n", |
1090 | 1090 | "\n",
|
1091 | 1091 | "Check out the use of the `partial` keyword to define two partial `Teacher` classes and even a **partial method** called `GetAge` that is defined in one part and executed from the other. Try removing the implementation of `GetAge` from the second class and see how the `DisplayAge` reflects this."
|
1092 | 1092 | ]
|
|
1157 | 1157 | "source": [
|
1158 | 1158 | "## Enumerations\n",
|
1159 | 1159 | "\n",
|
1160 |
| - "An [enumeration type](https://docs.microsoft.com/dotnet/csharp/language-reference/builtin-types/enum) is a value type that can be used to describe a collection of related named constants that actually reference an integral type. We use the `enum` keyword to define these types with an access modifier and the name of the type. Values are then listed, separated by commas inside the enum block.\n", |
| 1160 | + "An [enumeration type](https://docs.microsoft.com/dotnet/csharp/language-reference/builtin-types/enum?WT.mc_id=visualstudio-twitch-jefritz) is a value type that can be used to describe a collection of related named constants that actually reference an integral type. We use the `enum` keyword to define these types with an access modifier and the name of the type. Values are then listed, separated by commas inside the enum block.\n", |
1161 | 1161 | "\n",
|
1162 | 1162 | "By default, underlying values start with the value `0` and increment by `1`. Let's take a look at an example that describes the values of a dimmer lightswitch:"
|
1163 | 1163 | ]
|
|
1257 | 1257 | "\n",
|
1258 | 1258 | "Enums can also be used with bitwise operations so that you can store and pass along any number of values stored in one variable. Use the `[Flags]` attribute to instruct the C# compiler to enable this feature and set explicit binary values for the enum constants. You can use both integer values or binary values in your definitions.\n",
|
1259 | 1259 | "\n",
|
1260 |
| - "Then, you can store multiple values by using the bitwise OR operator `|` and can interact with those values [using other bitwise operators](https://docs.microsoft.com/dotnet/csharp/language-reference/operators/bitwise-and-shift-operators#enumeration-logical-operators)." |
| 1260 | + "Then, you can store multiple values by using the bitwise OR operator `|` and can interact with those values [using other bitwise operators](https://docs.microsoft.com/dotnet/csharp/language-reference/operators/bitwise-and-shift-operators#enumeration-logical-operators?WT.mc_id=visualstudio-twitch-jefritz)." |
1261 | 1261 | ]
|
1262 | 1262 | },
|
1263 | 1263 | {
|
|
0 commit comments