├── favicon.ico ├── .github ├── CODEOWNERS ├── PULL_REQUEST_TEMPLATE.md ├── workflows │ └── main.yml └── ISSUE_TEMPLATE.md ├── Finished ├── Language │ ├── Indexers │ │ ├── Indexers.csproj │ │ ├── Program.cs │ │ └── StockRecord.cs │ ├── IndexesRanges │ │ ├── IndexesRanges.csproj │ │ └── Program.cs │ ├── NullOperator │ │ ├── NullOperator.csproj │ │ └── Program.cs │ ├── LiteralNumbers │ │ ├── LiteralNumbers.csproj │ │ └── Program.cs │ ├── DeconstructCustom │ │ ├── DeconstructCustom.csproj │ │ ├── Program.cs │ │ └── Planet.cs │ └── DeconstructTuples │ │ ├── DeconstructTuples.csproj │ │ └── Program.cs ├── Events │ ├── BasicEvents │ │ ├── BasicEvents.csproj │ │ └── Program.cs │ ├── ChainedEvents │ │ ├── ChainedEvents.csproj │ │ └── Program.cs │ └── EventChallenge │ │ ├── EventChallenge.csproj │ │ └── Program.cs ├── Lambdas │ ├── BasicLambdas │ │ ├── BasicLambdas.csproj │ │ └── Program.cs │ ├── LambdaChallenge │ │ ├── LambdaChallenge.csproj │ │ └── Program.cs │ └── LambdaDelegates │ │ ├── LambdaDelegates.csproj │ │ └── Program.cs ├── PatternMatching │ ├── SwitchExpr │ │ ├── SwitchExpr.csproj │ │ ├── Shapes.cs │ │ └── Program.cs │ ├── BasicPatterns │ │ ├── BasicPatterns.csproj │ │ └── Program.cs │ ├── PositionalPatterns │ │ ├── PositionalPatterns.csproj │ │ └── Program.cs │ └── RelationalPatterns │ │ ├── RelationalPatterns.csproj │ │ └── Program.cs ├── Delegates │ ├── BasicDelegates │ │ ├── BasicDelegates.csproj │ │ └── Program.cs │ ├── AnonymousDelegates │ │ ├── AnonymousDelegates.csproj │ │ └── Program.cs │ └── ComposableDelegates │ │ ├── ComposableDelegates.csproj │ │ └── Program.cs └── Interfaces │ ├── BasicInterfaces │ ├── BasicInterfaces.csproj │ └── Program.cs │ ├── NETInterfaces │ ├── NETInterfaces.csproj │ └── Program.cs │ ├── CastingInterfaces │ ├── CastingInterfaces.csproj │ └── Program.cs │ ├── ExplicitInterfaces │ ├── ExplicitInterfaces.csproj │ └── Program.cs │ └── MultipleInterfaces │ ├── MultipleInterfaces.csproj │ └── Program.cs ├── Start ├── Events │ ├── BasicEvents │ │ ├── BasicEvents.csproj │ │ └── Program.cs │ ├── ChainedEvents │ │ ├── ChainedEvents.csproj │ │ └── Program.cs │ └── EventChallenge │ │ ├── EventChallenge.csproj │ │ └── Program.cs ├── Language │ ├── Indexers │ │ ├── Indexers.csproj │ │ ├── Program.cs │ │ └── StockRecord.cs │ ├── NullOperator │ │ ├── NullOperator.csproj │ │ └── Program.cs │ ├── IndexesRanges │ │ ├── IndexesRanges.csproj │ │ └── Program.cs │ ├── LiteralNumbers │ │ ├── LiteralNumbers.csproj │ │ └── Program.cs │ ├── DeconstructCustom │ │ ├── DeconstructCustom.csproj │ │ ├── Program.cs │ │ └── Planet.cs │ └── DeconstructTuples │ │ ├── DeconstructTuples.csproj │ │ └── Program.cs ├── Lambdas │ ├── BasicLambdas │ │ ├── BasicLambdas.csproj │ │ └── Program.cs │ ├── LambdaChallenge │ │ ├── LambdaChallenge.csproj │ │ └── Program.cs │ └── LambdaDelegates │ │ ├── LambdaDelegates.csproj │ │ └── Program.cs ├── Delegates │ ├── BasicDelegates │ │ ├── BasicDelegates.csproj │ │ └── Program.cs │ ├── AnonymousDelegates │ │ ├── AnonymousDelegates.csproj │ │ └── Program.cs │ └── ComposableDelegates │ │ ├── ComposableDelegates.csproj │ │ └── Program.cs ├── Interfaces │ ├── NETInterfaces │ │ ├── NETInterfaces.csproj │ │ └── Program.cs │ ├── BasicInterfaces │ │ ├── BasicInterfaces.csproj │ │ └── Program.cs │ ├── CastingInterfaces │ │ ├── CastingInterfaces.csproj │ │ └── Program.cs │ ├── ExplicitInterfaces │ │ ├── ExplicitInterfaces.csproj │ │ └── Program.cs │ └── MultipleInterfaces │ │ ├── MultipleInterfaces.csproj │ │ └── Program.cs └── PatternMatching │ ├── SwitchExpr │ ├── SwitchExpr.csproj │ ├── Shapes.cs │ └── Program.cs │ ├── BasicPatterns │ ├── BasicPatterns.csproj │ └── Program.cs │ ├── PositionalPatterns │ ├── PositionalPatterns.csproj │ └── Program.cs │ └── RelationalPatterns │ ├── RelationalPatterns.csproj │ └── Program.cs ├── CONTRIBUTING.md ├── NOTICE ├── .devcontainer ├── Dockerfile └── devcontainer.json ├── .vscode └── settings.json ├── README.md ├── .gitignore └── LICENSE /favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LinkedInLearning/advanced-c-sharp-programming-concepts-5914038/main/favicon.ico -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Codeowners for these exercise files: 2 | # * (asterisk) denotes "all files and folders" 3 | # Example: * @producer @instructor 4 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Finished/Language/Indexers/Indexers.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Start/Events/BasicEvents/BasicEvents.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Start/Language/Indexers/Indexers.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Finished/Events/BasicEvents/BasicEvents.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Start/Events/ChainedEvents/ChainedEvents.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Start/Lambdas/BasicLambdas/BasicLambdas.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Start/Language/NullOperator/NullOperator.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Finished/Events/ChainedEvents/ChainedEvents.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Finished/Events/EventChallenge/EventChallenge.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Finished/Lambdas/BasicLambdas/BasicLambdas.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Finished/Language/IndexesRanges/IndexesRanges.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Finished/Language/NullOperator/NullOperator.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Finished/PatternMatching/SwitchExpr/SwitchExpr.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Start/Delegates/BasicDelegates/BasicDelegates.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Start/Events/EventChallenge/EventChallenge.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Start/Interfaces/NETInterfaces/NETInterfaces.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Start/Lambdas/LambdaChallenge/LambdaChallenge.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Start/Lambdas/LambdaDelegates/LambdaDelegates.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Start/Language/IndexesRanges/IndexesRanges.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Start/Language/LiteralNumbers/LiteralNumbers.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Start/PatternMatching/SwitchExpr/SwitchExpr.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Finished/Delegates/BasicDelegates/BasicDelegates.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Finished/Interfaces/BasicInterfaces/BasicInterfaces.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Finished/Interfaces/NETInterfaces/NETInterfaces.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Finished/Lambdas/LambdaChallenge/LambdaChallenge.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Finished/Lambdas/LambdaDelegates/LambdaDelegates.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Finished/Language/LiteralNumbers/LiteralNumbers.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Start/Interfaces/BasicInterfaces/BasicInterfaces.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Start/Language/DeconstructCustom/DeconstructCustom.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Start/Language/DeconstructTuples/DeconstructTuples.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Start/PatternMatching/BasicPatterns/BasicPatterns.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Finished/Delegates/AnonymousDelegates/AnonymousDelegates.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Finished/Interfaces/CastingInterfaces/CastingInterfaces.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Finished/Language/DeconstructCustom/DeconstructCustom.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Finished/Language/DeconstructTuples/DeconstructTuples.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Finished/PatternMatching/BasicPatterns/BasicPatterns.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Start/Delegates/AnonymousDelegates/AnonymousDelegates.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Start/Delegates/ComposableDelegates/ComposableDelegates.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Start/Interfaces/CastingInterfaces/CastingInterfaces.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Start/Interfaces/ExplicitInterfaces/ExplicitInterfaces.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Start/Interfaces/MultipleInterfaces/MultipleInterfaces.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Finished/Delegates/ComposableDelegates/ComposableDelegates.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Finished/Interfaces/ExplicitInterfaces/ExplicitInterfaces.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Finished/Interfaces/MultipleInterfaces/MultipleInterfaces.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Start/PatternMatching/PositionalPatterns/PositionalPatterns.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Start/PatternMatching/RelationalPatterns/RelationalPatterns.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Finished/PatternMatching/PositionalPatterns/PositionalPatterns.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Finished/PatternMatching/RelationalPatterns/RelationalPatterns.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Copy To Branches 2 | on: 3 | workflow_dispatch: 4 | jobs: 5 | copy-to-branches: 6 | runs-on: ubuntu-latest 7 | steps: 8 | - uses: actions/checkout@v2 9 | with: 10 | fetch-depth: 0 11 | - name: Copy To Branches Action 12 | uses: planetoftheweb/copy-to-branches@v1.2 13 | env: 14 | key: main 15 | -------------------------------------------------------------------------------- /Start/Language/LiteralNumbers/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | 3 | // Numbers can be made more readable using _ as a number separator 4 | int d = 123456; 5 | float f = 1234.5f; 6 | var x = 0xABCDEF; 7 | var b = 0b1101111010010010; 8 | 9 | Console.WriteLine($"{d}"); 10 | Console.WriteLine($"{f}"); 11 | Console.WriteLine($"{b:X}"); 12 | Console.WriteLine($"{x:X}"); 13 | -------------------------------------------------------------------------------- /Finished/Language/LiteralNumbers/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | 3 | // Numbers can be made more readable using _ as a number separator 4 | int d = 123_456; 5 | float f = 1_234.5f; 6 | var x = 0xAB_CD_EF; 7 | var b = 0b1101_1110_1001_0010; 8 | 9 | Console.WriteLine($"{d}"); 10 | Console.WriteLine($"{f}"); 11 | Console.WriteLine($"{b:X}"); 12 | Console.WriteLine($"{x:X}"); 13 | -------------------------------------------------------------------------------- /Finished/PatternMatching/SwitchExpr/Shapes.cs: -------------------------------------------------------------------------------- 1 | // Example file for LinkedIn Learning Course "Advanced C#: Language Features by Joe Marini" 2 | // C# Pattern Matching using enhanced switch expressions 3 | 4 | public class Circle { 5 | public int Radius; 6 | } 7 | 8 | public class Rectangle { 9 | public int Length; 10 | public int Width; 11 | } 12 | 13 | public class Triangle { 14 | public int Base; 15 | public int Height; 16 | } 17 | -------------------------------------------------------------------------------- /Start/PatternMatching/SwitchExpr/Shapes.cs: -------------------------------------------------------------------------------- 1 | // Example file for LinkedIn Learning Course "Advanced C#: Language Features by Joe Marini" 2 | // C# Pattern Matching using enhanced switch expressions 3 | 4 | public class Circle { 5 | public int Radius; 6 | } 7 | 8 | public class Rectangle { 9 | public int Length; 10 | public int Width; 11 | } 12 | 13 | public class Triangle { 14 | public int Base; 15 | public int Height; 16 | } 17 | -------------------------------------------------------------------------------- /Start/Delegates/AnonymousDelegates/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Example file for anonymous delegates 3 | 4 | 5 | namespace AnonymousDelegates 6 | { 7 | public delegate string MyDelegate(int arg1, int arg2); 8 | 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | // TODO: Implement an anonymous delegate 14 | 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Start/Language/DeconstructCustom/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Using Deconstruction on a custom defined type 3 | 4 | // Create some classes with data 5 | Planet Earth = new Planet("Earth", 6371, 1, 150_980_000); 6 | Planet Venus = new Planet("Venus", 6052, 0, 108_930_000); 7 | 8 | // Use Deconstruction to get the name and moon count 9 | 10 | 11 | // Use Deconstruction to get the name, moon count, and radius 12 | -------------------------------------------------------------------------------- /Start/Language/Indexers/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Example file for using class indexers 3 | 4 | // Create a new sample data set 5 | StockRecord stock1 = new StockRecord(); 6 | 7 | // Access a couple of the properties 8 | Console.WriteLine($"Average: {stock1.Average:C}"); 9 | Console.WriteLine($"High: {stock1.High:C}"); 10 | Console.WriteLine($"Low: {stock1.Low:C}"); 11 | 12 | // Use the indexer method 13 | 14 | 15 | // Index using a different value 16 | -------------------------------------------------------------------------------- /Finished/Delegates/AnonymousDelegates/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Example file for anonymous delegates 3 | 4 | 5 | namespace AnonymousDelegates 6 | { 7 | 8 | public delegate string MyDelegate(int arg1, int arg2); 9 | 10 | class Program 11 | { 12 | static void Main(string[] args) 13 | { 14 | MyDelegate f = delegate(int arg1, int arg2) { 15 | return (arg1 + arg2).ToString(); 16 | }; 17 | 18 | Console.WriteLine("The number is: " + f(10,20)); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Finished/Language/DeconstructCustom/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Using Deconstruction on a custom defined type 3 | 4 | // Create some classes with data 5 | Planet Earth = new Planet("Earth", 6371, 1, 150_980_000); 6 | Planet Venus = new Planet("Venus", 6052, 0, 108_930_000); 7 | 8 | // Use Deconstruction to get the name and moon count 9 | var (name, moons) = Earth; 10 | Console.WriteLine($"{name}, {moons}"); 11 | 12 | // Use Deconstruction to get the name, moon count, and radius 13 | (name, moons, var radius) = Venus; 14 | Console.WriteLine($"{name}, {moons}, {radius}"); 15 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | 2 | Contribution Agreement 3 | ====================== 4 | 5 | This repository does not accept pull requests (PRs). All pull requests will be closed. 6 | 7 | However, if any contributions (through pull requests, issues, feedback or otherwise) are provided, as a contributor, you represent that the code you submit is your original work or that of your employer (in which case you represent you have the right to bind your employer). By submitting code (or otherwise providing feedback), you (and, if applicable, your employer) are licensing the submitted code (and/or feedback) to LinkedIn and the open source community subject to the BSD 2-Clause license. 8 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2025 LinkedIn Corporation 2 | All Rights Reserved. 3 | 4 | Licensed under the LinkedIn Learning Exercise File License (the "License"). 5 | See LICENSE in the project root for license information. 6 | 7 | Please note, this project may automatically load third party code from external 8 | repositories (for example, NPM modules, Composer packages, or other dependencies). 9 | If so, such third party code may be subject to other license terms than as set 10 | forth above. In addition, such third party code may also depend on and load 11 | multiple tiers of dependencies. Please review the applicable licenses of the 12 | additional dependencies. 13 | -------------------------------------------------------------------------------- /Start/Language/IndexesRanges/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Indexes and Ranges example 3 | 4 | // Define a sample array 5 | string[] words = [ 6 | "The","quick","brown","fox","jumps", 7 | "over","the","lazy","dog" 8 | ]; 9 | 10 | // The index operator provides access to array elements 11 | Console.WriteLine(words[1]); 12 | 13 | // The index-from-end operator indexes from the end of a sequence 14 | // (Note that the end is not zero-based, ^1 is the last item) 15 | 16 | 17 | // The range operator (..) defines a range 18 | 19 | 20 | // Indexes and ranges can be variables too 21 | 22 | -------------------------------------------------------------------------------- /Start/Lambdas/BasicLambdas/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Example file for basic lambda functions 3 | 4 | namespace BasicLambdas 5 | { 6 | // define a few delegate types 7 | public delegate int MyDelegate(int x); 8 | public delegate void MyDelegate2(int x, string prefix); 9 | 10 | class Program 11 | { 12 | static void Main(string[] args) 13 | { 14 | // Create a basic delegate that squares a number 15 | 16 | // Dynamically change the delegate to something else 17 | 18 | // Create a delegate that takes multiple arguments 19 | 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Start/Language/NullOperator/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Example file for the null coalescing operator 3 | 4 | // A common scenario is to test a value for null and assign one if it is 5 | void OldSchoolLogString(string? theString) { 6 | if (theString == null) { 7 | Console.WriteLine("No string given!"); 8 | } 9 | else { 10 | Console.WriteLine(theString); 11 | } 12 | } 13 | 14 | OldSchoolLogString("Test String"); 15 | OldSchoolLogString(null); 16 | 17 | // the ?? operator returns the left-hand value if not null, or the right one if it is null 18 | 19 | 20 | 21 | // It's also allowable to throw an exception as part of the right-hand expression 22 | 23 | 24 | // The ??= assigns a value if the left-hand value is null 25 | -------------------------------------------------------------------------------- /Start/Language/DeconstructCustom/Planet.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Using Deconstruction on a custom defined type 3 | 4 | public class Planet 5 | { 6 | public string Name { get; set; } 7 | public int Radius { get; set; } 8 | public int MoonCount { get; set; } 9 | public int DistanceFromSunKm { get; set; } 10 | 11 | public Planet(string name, int rads, int moons, int distance ) { 12 | Name = name; 13 | Radius = rads; 14 | MoonCount = moons; 15 | DistanceFromSunKm = distance; 16 | } 17 | 18 | // Define a Deconstruct method to return the name and moon count 19 | 20 | 21 | // Define a Deconstruct method to return the name, moon count, and radius 22 | 23 | 24 | // Defining a Deconstruct with the name number of parameters will cause an error 25 | } 26 | -------------------------------------------------------------------------------- /Finished/Language/Indexers/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Example file for using class indexers 3 | 4 | // Create a new sample data set 5 | StockRecord stock1 = new StockRecord(); 6 | 7 | // Access a couple of the properties 8 | Console.WriteLine($"Days: {stock1.Length}"); 9 | Console.WriteLine($"Average: {stock1.Average:C}"); 10 | Console.WriteLine($"High: {stock1.High:C}"); 11 | Console.WriteLine($"Low: {stock1.Low:C}"); 12 | 13 | // Use the indexer method 14 | for (int i=0; i < stock1.Length; i++) { 15 | decimal val = stock1[i]; 16 | Console.Write($"Val: {val:C} "); 17 | } 18 | Console.WriteLine(""); 19 | 20 | // Index using a different value 21 | Console.WriteLine($"Monday: {stock1["mon"]:C}"); 22 | Console.WriteLine($"Wednesday: {stock1["wed"]:C}"); 23 | Console.WriteLine($"Wednesday: {stock1["sat"]:C}"); 24 | -------------------------------------------------------------------------------- /Start/Delegates/BasicDelegates/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Example file for basic delegates 3 | 4 | namespace BasicDelegates 5 | { 6 | // TODO: declare the delegate type 7 | 8 | 9 | class MyClass 10 | { 11 | // Delegates can be bound to instance members as well as 12 | // static class functions 13 | public string instanceMethod1(int arg1, int arg2) 14 | { 15 | return ((arg1 + arg2) * arg1).ToString(); 16 | } 17 | } 18 | 19 | class Program 20 | { 21 | // TODO: Create functions to serve as delegate implementations 22 | 23 | 24 | static void Main(string[] args) 25 | { 26 | // TODO: exercise each delegate function 27 | 28 | 29 | // TODO: Use an instance function of a class as a delegate 30 | 31 | 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /.devcontainer/Dockerfile: -------------------------------------------------------------------------------- 1 | # [Choice] .NET version: 6.0, 3.1, 6.0-bullseye, 3.1-bullseye, 6.0-focal, 3.1-focal 2 | #ARG VARIANT=6.0-bullseye 3 | #FROM mcr.microsoft.com/vscode/devcontainers/dotnet:0-${VARIANT} 4 | ARG VARIANT=9.0-bookworm 5 | FROM mcr.microsoft.com/devcontainers/dotnet:1-${VARIANT} 6 | 7 | # [Choice] Node.js version: none, lts/*, 18, 16, 14 8 | ARG NODE_VERSION="none" 9 | RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi 10 | 11 | # [Optional] Uncomment this section to install additional OS packages. 12 | # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ 13 | # && apt-get -y install --no-install-recommends 14 | 15 | # [Optional] Uncomment this line to install global node packages. 16 | # RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g " 2>&1 17 | -------------------------------------------------------------------------------- /Start/Events/EventChallenge/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Example file for Event Challenge 3 | 4 | namespace EventsChallenge 5 | { 6 | class PiggyBank { 7 | private decimal _BalanceAmount; 8 | 9 | public decimal TheBalance { 10 | set { 11 | _BalanceAmount = value; 12 | } 13 | get { 14 | return _BalanceAmount; 15 | } 16 | } 17 | } 18 | 19 | class Program { 20 | static void Main(string[] args) { 21 | decimal[] testValues = { 250, 1000, -750, 100, -200 }; 22 | 23 | PiggyBank pb = new PiggyBank(); 24 | 25 | foreach (decimal testValue in testValues) { 26 | pb.TheBalance += testValue; 27 | } 28 | Console.WriteLine($"Final value is {pb.TheBalance}"); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Start/Interfaces/ExplicitInterfaces/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Example file for explicit interfaces 3 | 4 | namespace ExplicitInterfaces 5 | { 6 | interface Intf1 7 | { 8 | void SomeMethod(); 9 | } 10 | interface Intf2 11 | { 12 | void SomeMethod(); 13 | } 14 | 15 | // TODO: Implement two interfaces with conflicting methods 16 | class InterfaceTest 17 | { 18 | // TODO: Implement Intf1 and Intf2 SomeMethod 19 | 20 | public void SomeMethod() { 21 | Console.WriteLine("This is the class SomeMethod"); 22 | } 23 | } 24 | 25 | class Program 26 | { 27 | static void Main(string[] args) { 28 | InterfaceTest testclass = new InterfaceTest(); 29 | testclass.SomeMethod(); 30 | 31 | // TODO: Call SomeMethod in the two interfaces 32 | 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Start/Interfaces/BasicInterfaces/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Example file for implementing basic interfaces 3 | 4 | namespace BasicInterfaces 5 | { 6 | // TODO: Define an IStorable interface that provides the ability to load and 7 | // save the information for an object 8 | 9 | 10 | // TODO: Implement IStorable on the Document class 11 | class Document 12 | { 13 | private string name; 14 | 15 | public Document(string s) 16 | { 17 | name = s; 18 | Console.WriteLine("Created a document with name '{0}'", s); 19 | } 20 | 21 | // TODO: Implement the IStorable interface methods and properties 22 | } 23 | 24 | class Program 25 | { 26 | static void Main(string[] args) { 27 | Document d = new Document("Test Document"); 28 | 29 | // TODO: Exercise the IStorable interface 30 | 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Start/Language/Indexers/StockRecord.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Example file for using class indexers 3 | 4 | // StockRecord is a sample class that returns information about 5 | // a week's worth of stock information - closing prices, etc. 6 | public class StockRecord { 7 | public string Symbol { 8 | get => "ABCD"; 9 | } 10 | 11 | private decimal[] prices = new decimal[] { 12 | 105.1m, 103.12m, 106.93m, 104.5m, 103.7m 13 | }; 14 | 15 | // Define some public properties 16 | public decimal Average { 17 | get => prices.Sum() / prices.Length; 18 | } 19 | public decimal High { 20 | get => prices.Max(); 21 | } 22 | public decimal Low { 23 | get => prices.Min(); 24 | } 25 | 26 | // TODO: implement Length property 27 | 28 | 29 | // TODO: implement this[] to enable indexing 30 | 31 | // TODO: You can overload the indexer to provide another way to access 32 | 33 | } 34 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.bracketPairColorization.enabled": true, 3 | "editor.cursorBlinking": "solid", 4 | "editor.fontFamily": "ui-monospace, Menlo, Monaco, 'Cascadia Mono', 'Segoe UI Mono', 'Roboto Mono', 'Oxygen Mono', 'Ubuntu Monospace', 'Source Code Pro', 'Fira Mono', 'Droid Sans Mono', 'Courier New', monospace", 5 | "editor.fontLigatures": false, 6 | "editor.fontSize": 20, 7 | "editor.formatOnPaste": true, 8 | "editor.formatOnSave": true, 9 | "editor.lineNumbers": "on", 10 | "editor.matchBrackets": "always", 11 | "editor.minimap.enabled": false, 12 | "editor.smoothScrolling": true, 13 | "editor.tabSize": 2, 14 | "editor.useTabStops": true, 15 | "emmet.triggerExpansionOnTab": true, 16 | "files.autoSave": "afterDelay", 17 | "terminal.integrated.fontSize": 18, 18 | "workbench.colorTheme": "Visual Studio Light", 19 | "workbench.fontAliasing": "antialiased", 20 | "workbench.statusBar.visible": true, 21 | "terminal.integrated.defaultProfile.linux": "pwsh" 22 | } -------------------------------------------------------------------------------- /Finished/Lambdas/BasicLambdas/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Example file for basic lambda functions 3 | 4 | namespace BasicLambdas 5 | { 6 | // define a few delegate types 7 | public delegate int MyDelegate(int x); 8 | public delegate void MyDelegate2(int x, string prefix); 9 | 10 | class Program 11 | { 12 | static void Main(string[] args) 13 | { 14 | // Create a basic delegate that squares a number 15 | MyDelegate func1 = (x) => x * x; 16 | Console.WriteLine("The result of foo is: {0}", func1(5)); 17 | 18 | // Dynamically change the delegate to something else 19 | func1 = (x) => x * 10; 20 | Console.WriteLine("The result of bar is: {0}", func1(5)); 21 | 22 | // Create a delegate that takes multiple arguments 23 | MyDelegate2 func2 = (x, y) => { 24 | Console.WriteLine("The two-arg lambda: {1}, {0}", x * 10, y); 25 | }; 26 | func2(25, "Some string"); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 7 | 8 | ## Issue Overview 9 | 10 | 11 | ## Describe your environment 12 | 13 | 14 | ## Steps to Reproduce 15 | 16 | 1. 17 | 2. 18 | 3. 19 | 4. 20 | 21 | ## Expected Behavior 22 | 23 | 24 | ## Current Behavior 25 | 26 | 27 | ## Possible Solution 28 | 29 | 30 | ## Screenshots / Video 31 | 32 | 33 | ## Related Issues 34 | 35 | -------------------------------------------------------------------------------- /Finished/Interfaces/ExplicitInterfaces/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Example file for explicit interfaces 3 | 4 | namespace ExplicitInterfaces 5 | { 6 | interface Intf1 7 | { 8 | void SomeMethod(); 9 | } 10 | interface Intf2 11 | { 12 | void SomeMethod(); 13 | } 14 | 15 | class InterfaceTest : Intf1, Intf2 16 | { 17 | void Intf1.SomeMethod() { 18 | Console.WriteLine("This is Intf1's SomeMethod"); 19 | } 20 | void Intf2.SomeMethod() { 21 | Console.WriteLine("This is Intf2's SomeMethod"); 22 | } 23 | public void SomeMethod() { 24 | Console.WriteLine("This is the class SomeMethod"); 25 | } 26 | } 27 | 28 | class Program 29 | { 30 | static void Main(string[] args) { 31 | InterfaceTest testclass = new InterfaceTest(); 32 | testclass.SomeMethod(); 33 | 34 | Intf1 i1 = testclass as Intf1; 35 | i1.SomeMethod(); 36 | 37 | Intf2 i2 = testclass as Intf2; 38 | i2.SomeMethod(); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Finished/Language/IndexesRanges/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Indexes and Ranges example 3 | 4 | // Define a sample array 5 | string[] words = [ 6 | "The","quick","brown","fox","jumps", 7 | "over","the","lazy","dog" 8 | ]; 9 | 10 | // The index operator provides access to array elements 11 | Console.WriteLine(words[1]); 12 | 13 | // The index-from-end operator indexes from the end of a sequence 14 | // (Note that the end is not zero-based, ^1 is the last item) 15 | Console.WriteLine(words[^1]); 16 | 17 | // The range operator (..) defines a range 18 | string[] wordRange = words[2..5]; 19 | Console.WriteLine($"{string.Join(",",wordRange)}"); 20 | wordRange = words[..]; 21 | Console.WriteLine($"{string.Join(",",wordRange)}"); 22 | wordRange = words[..5]; 23 | Console.WriteLine($"{string.Join(",",wordRange)}"); 24 | wordRange = words[2..]; 25 | Console.WriteLine($"{string.Join(",",wordRange)}"); 26 | 27 | // Indexes and ranges can be variables too 28 | Index idx = ^4; 29 | Console.WriteLine(words[idx]); 30 | 31 | Range rng = 3..^1; 32 | wordRange = words[rng]; 33 | Console.WriteLine($"{string.Join(",",wordRange)}"); 34 | -------------------------------------------------------------------------------- /Start/PatternMatching/RelationalPatterns/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Using Relational Patterns in Pattern Matching 3 | 4 | // Relational patterns can be used to compare constant values using logical comparison 5 | // operators such as <, >, <=, and >= 6 | 7 | // Example: Given a Date, determine which quarter it occurs in 8 | string GetQuarterFromDate(DateTime date) => date.Month switch 9 | { 10 | // TODO: Categorize the date into a quarter 11 | 12 | _ => throw new ArgumentOutOfRangeException(nameof(date), $"Unexpected month given: {date.Month}."), 13 | }; 14 | 15 | // Console.WriteLine(GetQuarterFromDate(new DateTime(2028, 2, 14))); 16 | // Console.WriteLine(GetQuarterFromDate(new DateTime(2028, 7, 19))); 17 | // Console.WriteLine(GetQuarterFromDate(new DateTime(2028, 12, 25))); 18 | // Console.WriteLine(GetQuarterFromDate(new DateTime(2028, 4, 1))); 19 | 20 | // This also works with the regular "is" statement 21 | void FirstOrSecondHalf(object dt) { 22 | // TODO: Categorize the date into a half 23 | 24 | } 25 | // FirstOrSecondHalf(new DateTime(2028, 7, 28)); 26 | // FirstOrSecondHalf(new DateTime(2028, 4, 1)); 27 | -------------------------------------------------------------------------------- /Start/Interfaces/CastingInterfaces/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Example file for casting interfaces 3 | 4 | namespace CastingInterfaces 5 | { 6 | interface IStorable 7 | { 8 | void Save(); 9 | void Load(); 10 | Boolean NeedsSave { get; set; } 11 | } 12 | 13 | class Document : IStorable 14 | { 15 | private string name; 16 | 17 | public Document(string s) { 18 | name = s; 19 | Console.WriteLine("Created a document with name '{0}'", s); 20 | } 21 | 22 | public void Save() { 23 | Console.WriteLine("Saving the document"); 24 | } 25 | 26 | public void Load() { 27 | Console.WriteLine("Loading the document"); 28 | } 29 | 30 | public Boolean NeedsSave { 31 | get; set; 32 | } 33 | } 34 | 35 | class Program 36 | { 37 | static void Main(string[] args) { 38 | Document d = new Document("Test Document"); 39 | 40 | // TODO: Use the 'is' operator 41 | 42 | // TODO: Use the 'as' operator 43 | 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Start/Language/DeconstructTuples/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Example file for using deconstruction of an object using tuples 3 | 4 | // Tuples provide an easy, lightweight way of returning multiple values 5 | // from a single function call without defining a complex structure 6 | (decimal, decimal, decimal) GetStockValues(string ticker) { 7 | // Given a ticker symbol, return HIGH, LOW, and CLOSE values 8 | if (ticker == "ABCD") { 9 | return (22.0m, 19.0m, 20.5m); 10 | } 11 | else if (ticker == "WXYZ") { 12 | return (50.0m, 47.0m, 49.25m); 13 | } 14 | else { 15 | return (0,0,0); 16 | } 17 | } 18 | 19 | // Working directly with a tuple can be somewhat tedious, having 20 | // to access each value individually using the ItemN syntax: 21 | var result = GetStockValues("ABCD"); 22 | Console.WriteLine($"{result.Item1}, {result.Item2}, {result.Item3}"); 23 | 24 | // An easier way can be accomplished using named values and 25 | // deconstructing the tuple into variables 26 | 27 | 28 | // You can also use explicit variable types, and the _ character can be 29 | // used to ignore any values that you don't plan to use 30 | -------------------------------------------------------------------------------- /Finished/Language/NullOperator/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Example file for the null coalescing operator 3 | 4 | // A common scenario is to test a value for null and assign one if it is 5 | void OldSchoolLogString(string? theString) { 6 | if (theString == null) { 7 | Console.WriteLine("No string given!"); 8 | } 9 | else { 10 | Console.WriteLine(theString); 11 | } 12 | } 13 | 14 | OldSchoolLogString("Test String"); 15 | OldSchoolLogString(null); 16 | 17 | // the ?? operator returns the left-hand value if not null, or the right one if it is null 18 | void LogString(string? theString) { 19 | Console.WriteLine(theString ?? "No string given!"); 20 | } 21 | 22 | LogString("Test String"); 23 | LogString(null); 24 | 25 | // It's also allowable to throw an exception as part of the right-hand expression 26 | void ThrowableLogString(string? theString) { 27 | Console.WriteLine(theString ?? throw new ArgumentNullException("theString","Cannot be null!")); 28 | } 29 | 30 | ThrowableLogString("Test String"); 31 | ThrowableLogString(null); 32 | 33 | // The ??= assigns a value if the left-hand value is null 34 | string str = null; 35 | str ??= "Default value"; 36 | Console.WriteLine(str); 37 | -------------------------------------------------------------------------------- /Start/PatternMatching/SwitchExpr/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // C# Pattern Matching using enhanced switch expressions 3 | 4 | // switch statements are very common in C#: 5 | string NumToString(int num) { 6 | switch (num) { 7 | case 1: 8 | return "One"; 9 | case 2: 10 | return "Two"; 11 | case 3: 12 | return "Three"; 13 | default: 14 | return "Unknown"; 15 | } 16 | } 17 | Console.WriteLine(NumToString(2)); 18 | Console.WriteLine(NumToString(4)); 19 | 20 | // switch statements can operate on just about any type 21 | // string ShapeToString(object shape) { 22 | // } 23 | // Console.WriteLine(ShapeToString(new Circle { Radius = 10 })); 24 | // Console.WriteLine(ShapeToString(new Rectangle { Length = 5, Width = 10 })); 25 | 26 | 27 | // This can be made a little more concise with the switch expression 28 | // string ShapeToString2(object shape) => { 29 | // } 30 | // Console.WriteLine(ShapeToString2(new Circle { Radius = 20 })); 31 | // Console.WriteLine(ShapeToString2(new Circle { Radius = 10 })); 32 | // Console.WriteLine(ShapeToString2(new Rectangle { Length = 10, Width = 10 })); 33 | // Console.WriteLine(ShapeToString2(new Rectangle { Length = 5, Width = 10 })); 34 | -------------------------------------------------------------------------------- /Start/Interfaces/MultipleInterfaces/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Example file for multiple interfaces 3 | 4 | namespace MultipleInterfaces 5 | { 6 | interface IStorable 7 | { 8 | void Save(); 9 | void Load(); 10 | Boolean NeedsSave { get; set; } 11 | } 12 | 13 | // TODO: Create an IEncryptable interface 14 | 15 | // TODO: Implement from both interfaces 16 | class Document : IStorable 17 | { 18 | private string name; 19 | 20 | public Document(string s) { 21 | name = s; 22 | Console.WriteLine("Created a document with name '{0}'", s); 23 | } 24 | 25 | public void Save() { 26 | Console.WriteLine("Saving the document"); 27 | } 28 | 29 | public void Load() { 30 | Console.WriteLine("Loading the document"); 31 | } 32 | 33 | public Boolean NeedsSave { 34 | get; set; 35 | } 36 | 37 | // TODO: Implement IEncryptable 38 | } 39 | 40 | class Program 41 | { 42 | static void Main(string[] args) { 43 | Document d = new Document("Test Document"); 44 | 45 | // TODO: Exercise the interfaces 46 | 47 | } 48 | } 49 | } 50 | 51 | -------------------------------------------------------------------------------- /Finished/Language/DeconstructCustom/Planet.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Using Deconstruction on a custom defined type 3 | 4 | public class Planet 5 | { 6 | public string Name { get; set; } 7 | public int Radius { get; set; } 8 | public int MoonCount { get; set; } 9 | public int DistanceFromSunKm { get; set; } 10 | 11 | public Planet(string name, int rads, int moons, int distance ) { 12 | Name = name; 13 | Radius = rads; 14 | MoonCount = moons; 15 | DistanceFromSunKm = distance; 16 | } 17 | 18 | // Define a Deconstruct method to return the name and moon count 19 | public void Deconstruct(out string name, out int moons) { 20 | name = Name; 21 | moons = MoonCount; 22 | } 23 | 24 | // Define a Deconstruct method to return the name, moon count, and radius 25 | public void Deconstruct(out string name, out int moons, out int radius) { 26 | name = Name; 27 | moons = MoonCount; 28 | radius = Radius; 29 | } 30 | 31 | // Defining a Deconstruct with the name number of parameters will cause an error 32 | // public void Deconstruct(out string name, out int distance) { 33 | // name = Name; 34 | // moons = DistanceFromSunKm; 35 | // } 36 | } -------------------------------------------------------------------------------- /Start/Lambdas/LambdaChallenge/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Example file for Lambda Challenge 3 | 4 | namespace EventsSolution 5 | { 6 | public delegate void BalanceEventHandler(decimal OldValue, decimal NewValue); 7 | 8 | class PiggyBank { 9 | private decimal _BalanceAmount; 10 | public event BalanceEventHandler? BalanceChanged; 11 | 12 | public decimal TheBalance { 13 | set { 14 | decimal oldVal = _BalanceAmount; 15 | _BalanceAmount = value; 16 | if (BalanceChanged is not null) { BalanceChanged(oldVal, _BalanceAmount); } 17 | } 18 | get { 19 | return _BalanceAmount; 20 | } 21 | } 22 | } 23 | 24 | class Program { 25 | static void Main(string[] args) { 26 | decimal[] testValues = { 250, 1000, -750, 100, -200 }; 27 | 28 | PiggyBank pb = new PiggyBank(); 29 | 30 | // TODO: Use a lambda function to implement the event handler 31 | 32 | foreach (decimal testValue in testValues) { 33 | pb.TheBalance += testValue; 34 | } 35 | Console.WriteLine($"Final value is {pb.TheBalance}"); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Finished/Delegates/BasicDelegates/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Example file for basic delegates 3 | 4 | namespace BasicDelegates 5 | { 6 | // declare the delegate type 7 | public delegate string MyDelegate(int arg1, int arg2); 8 | 9 | class MyClass 10 | { 11 | // Delegates can be bound to instance members as well as 12 | // static class functions 13 | public string instanceMethod1(int arg1, int arg2) 14 | { 15 | return ((arg1 + arg2) * arg1).ToString(); 16 | } 17 | } 18 | 19 | class Program 20 | { 21 | static string func1(int a, int b) 22 | { 23 | return (a + b).ToString(); 24 | } 25 | 26 | static string func2(int a, int b) 27 | { 28 | return (a * b).ToString(); 29 | } 30 | 31 | static void Main(string[] args) 32 | { 33 | MyDelegate f = func1; 34 | Console.WriteLine("The number is: " + f(10, 20)); 35 | f = func2; 36 | Console.WriteLine("The number is: " + f(10, 20)); 37 | 38 | MyClass mc = new MyClass(); 39 | f = mc.instanceMethod1; 40 | Console.WriteLine("The number is: " + f(10, 20)); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ASPNET", 3 | // Configure tool-specific properties. 4 | "build": { 5 | "dockerfile": "Dockerfile", 6 | "args": { 7 | // Update 'VARIANT' to pick a .NET Core version: 3.1, 6.0 8 | // Append -bullseye or -focal to pin to an OS version. 9 | // "VARIANT": "6.0-bullseye", 10 | "VARIANT": "9.0-bookworm", 11 | // Options 12 | "NODE_VERSION": "lts/*" 13 | } 14 | }, 15 | "customizations": { 16 | "codespaces": { 17 | "openFiles": [ 18 | "README.md" 19 | ] 20 | }, 21 | // Configure properties specific to VS Code. 22 | "vscode": { 23 | // Add the IDs of extensions you want installed when the container is created. 24 | "extensions": [ 25 | "linkedinlearning.linkedinlearning-vscode-theme", 26 | "ms-dotnettools.csharp" 27 | ] 28 | } 29 | }, 30 | // Use 'forwardPorts' to make a list of ports inside the container available locally. 31 | // "forwardPorts": [], 32 | // Use 'postCreateCommand' to run commands after the container is created. 33 | // "postCreateCommand": "gcc -v", 34 | "onCreateCommand": "echo PS1='\"$ \"' >> ~/.bashrc && dotnet dev-certs https", //Set Terminal Prompt to $ 35 | // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. 36 | "remoteUser": "vscode", 37 | "features": { 38 | "powershell": "latest" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Finished/Lambdas/LambdaChallenge/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Example file for Lambda Challenge 3 | 4 | namespace EventsSolution 5 | { 6 | public delegate void BalanceEventHandler(decimal OldValue, decimal NewValue); 7 | 8 | class PiggyBank { 9 | private decimal _BalanceAmount; 10 | public event BalanceEventHandler? BalanceChanged; 11 | 12 | public decimal TheBalance { 13 | set { 14 | decimal oldVal = _BalanceAmount; 15 | _BalanceAmount = value; 16 | if (BalanceChanged is not null) { BalanceChanged(oldVal, _BalanceAmount); } 17 | } 18 | get { 19 | return _BalanceAmount; 20 | } 21 | } 22 | } 23 | 24 | class Program { 25 | static void Main(string[] args) { 26 | decimal[] testValues = { 250, 1000, -750, 100, -200 }; 27 | 28 | PiggyBank pb = new PiggyBank(); 29 | 30 | pb.BalanceChanged += (OldAmount, NewAmount) => Console.WriteLine($"The balance changed from {OldAmount} to {NewAmount}"); 31 | 32 | foreach (decimal testValue in testValues) { 33 | pb.TheBalance += testValue; 34 | } 35 | Console.WriteLine($"Final value is {pb.TheBalance}"); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Finished/Interfaces/CastingInterfaces/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Example file for casting interfaces 3 | 4 | namespace CastingInterfaces 5 | { 6 | interface IStorable 7 | { 8 | void Save(); 9 | void Load(); 10 | bool NeedsSave { get; set; } 11 | } 12 | 13 | class Document : IStorable 14 | { 15 | private string name; 16 | 17 | public Document(string s) { 18 | name = s; 19 | Console.WriteLine("Created a document with name '{0}'", s); 20 | } 21 | 22 | public void Save() { 23 | Console.WriteLine("Saving the document"); 24 | } 25 | 26 | public void Load() { 27 | Console.WriteLine("Loading the document"); 28 | } 29 | 30 | public bool NeedsSave { 31 | get; set; 32 | } 33 | } 34 | 35 | class Program 36 | { 37 | static void Main(string[] args) { 38 | Document d = new Document("Test Document"); 39 | 40 | // Use the 'is' operator 41 | if (d is IStorable) { 42 | d.Save(); 43 | } 44 | 45 | // Use the 'as' operator 46 | IStorable istor = d as IStorable; 47 | if (istor != null) { 48 | istor.Load(); 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Finished/Language/DeconstructTuples/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Example file for using deconstruction of an object using tuples 3 | 4 | // Tuples provide an easy, lightweight way of returning multiple values 5 | // from a single function call without defining a complex structure 6 | (decimal, decimal, decimal) GetStockValues(string ticker) { 7 | // Given a ticker symbol, return HIGH, LOW, and CLOSE values 8 | if (ticker == "ABCD") { 9 | return (22.0m, 19.0m, 20.5m); 10 | } 11 | else if (ticker == "WXYZ") { 12 | return (50.0m, 47.0m, 49.25m); 13 | } 14 | else { 15 | return (0,0,0); 16 | } 17 | } 18 | 19 | // Working directly with a tuple can be somewhat tedious, having 20 | // to access each value individually using the ItemN syntax: 21 | var result = GetStockValues("ABCD"); 22 | Console.WriteLine($"{result.Item1}, {result.Item2}, {result.Item3}"); 23 | 24 | // An easier way can be accomplished using named values and 25 | // deconstructing the tuple into variables 26 | var (high, low, close) = GetStockValues("WXYZ"); 27 | Console.WriteLine($"{high}, {low}, {close}"); 28 | 29 | // You can also use explicit variable types, and the _ character can be 30 | // used to ignore any values that you don't plan to use 31 | decimal cl; 32 | (_, _, cl) = GetStockValues("ABCD"); 33 | Console.WriteLine($"{cl}"); 34 | -------------------------------------------------------------------------------- /Finished/Interfaces/BasicInterfaces/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Example file for implementing basic interfaces 3 | 4 | namespace BasicInterfaces 5 | { 6 | // Define an IStorable interface that provides the ability to load and 7 | // save the information for an object 8 | interface IStorable 9 | { 10 | void Save(); 11 | void Load(); 12 | bool NeedsSave { get; set; } 13 | } 14 | 15 | // Implement IStorable on the Document class 16 | class Document : IStorable 17 | { 18 | private string name; 19 | 20 | public Document(string s) { 21 | name = s; 22 | Console.WriteLine("Created a document with name '{0}'", s); 23 | } 24 | 25 | // Implement the IStorable interface methods and properties 26 | public void Save() { 27 | Console.WriteLine("Saving the document"); 28 | } 29 | 30 | public void Load() { 31 | Console.WriteLine("Loading the document"); 32 | } 33 | 34 | public bool NeedsSave { 35 | get; set; 36 | } 37 | } 38 | 39 | class Program 40 | { 41 | static void Main(string[] args) { 42 | Document d = new Document("Test Document"); 43 | 44 | // Exercise the IStorable interface 45 | d.Load(); 46 | d.Save(); 47 | d.NeedsSave = false; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Finished/Delegates/ComposableDelegates/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Example file for composable delegates 3 | 4 | 5 | namespace ComposableDelegates 6 | { 7 | // declare the delegate type 8 | public delegate void MyDelegate(int arg1, int arg2); 9 | 10 | class Program 11 | { 12 | static void func1(int arg1, int arg2) 13 | { 14 | string result = (arg1 + arg2).ToString(); 15 | Console.WriteLine("The number is: " + result); 16 | } 17 | 18 | static void func2(int arg1, int arg2) 19 | { 20 | string result = (arg1 * arg2).ToString(); 21 | Console.WriteLine("The number is: " + result); 22 | } 23 | 24 | static void Main(string[] args) 25 | { 26 | MyDelegate? f1 = func1; 27 | MyDelegate? f2 = func2; 28 | MyDelegate? f1f2 = f1 + f2; 29 | 30 | // call each delegate and then the chain 31 | Console.WriteLine("Calling the first delegate"); 32 | f1(10, 20); 33 | Console.WriteLine("Calling the second delegate"); 34 | f2(10, 20); 35 | Console.WriteLine("\nCalling the chained delegates"); 36 | f1f2(10, 20); 37 | 38 | // subtract off one of the delegates 39 | Console.WriteLine("\nCalling the unchained delegates"); 40 | f1f2 -= f1; 41 | f1f2(20, 20); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Start/Lambdas/LambdaDelegates/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Example file for lambdas as delegates 3 | 4 | namespace LambdaDelegates 5 | { 6 | // define a delegate 7 | public delegate void myEventHandler(string value); 8 | 9 | class MyClass 10 | { 11 | private string? theVal = null; 12 | public event myEventHandler? valueChanged; // no need to initialize to null, defaults to null 13 | 14 | public string Val 15 | { 16 | set 17 | { 18 | this.theVal = value; 19 | // when the value changes, fire the event 20 | this.valueChanged?.Invoke(theVal); // safe invocation 21 | } 22 | } 23 | } 24 | 25 | class Program 26 | { 27 | static void Main(string[] args) 28 | { 29 | MyClass obj = new MyClass(); 30 | 31 | // TODO: Use a Lambda expression to define an event handler 32 | // Note that this is a statement lambda, due to use of { } 33 | 34 | string? str; 35 | do 36 | { 37 | Console.WriteLine("Enter a value, or 'exit' to exit:"); 38 | str = Console.ReadLine(); 39 | if (!str!.Equals("exit")) 40 | { 41 | obj.Val = str; 42 | } 43 | } while (!str.Equals("exit")); 44 | 45 | Console.WriteLine("Goodbye!"); 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /Finished/Events/EventChallenge/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Example file for Event Challenge 3 | 4 | namespace EventsSolution 5 | { 6 | public delegate void BalanceEventHandler(decimal OldValue, decimal NewValue); 7 | 8 | class PiggyBank { 9 | private decimal _BalanceAmount; 10 | public event BalanceEventHandler? BalanceChanged; 11 | 12 | public decimal TheBalance { 13 | set { 14 | decimal oldVal = _BalanceAmount; 15 | _BalanceAmount = value; 16 | if (BalanceChanged is not null) { BalanceChanged(oldVal, _BalanceAmount); } 17 | } 18 | get { 19 | return _BalanceAmount; 20 | } 21 | } 22 | } 23 | 24 | class BalanceLogger { 25 | public static void BalanceLog(decimal oldVal, decimal newVal) { 26 | Console.WriteLine($"The balance changed from {oldVal} to {newVal}"); 27 | } 28 | } 29 | 30 | class Program { 31 | static void Main(string[] args) { 32 | decimal[] testValues = { 250, 1000, -750, 100, -200 }; 33 | 34 | PiggyBank pb = new PiggyBank(); 35 | 36 | pb.BalanceChanged += BalanceLogger.BalanceLog; 37 | 38 | foreach (decimal testValue in testValues) { 39 | pb.TheBalance += testValue; 40 | } 41 | Console.WriteLine($"Final value is {pb.TheBalance}"); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Finished/PatternMatching/RelationalPatterns/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Using Relational Patterns in Pattern Matching 3 | 4 | // Relational patterns can be used to compare constant values using logical comparison 5 | // operators such as <, >, <=, and >= 6 | 7 | // Example: Given a Date, determine which quarter it occurs in 8 | string GetQuarterFromDate(DateTime date) => date.Month switch 9 | { 10 | // TODO: Categorize the date into a quarter 11 | >= 1 and <= 3 => "Q1", 12 | >= 4 and <= 6 => "Q2", 13 | >= 7 and <= 9 => "Q3", 14 | >= 10 and <= 12 => "Q4", 15 | _ => throw new ArgumentOutOfRangeException(nameof(date), $"Unexpected month given: {date.Month}."), 16 | }; 17 | 18 | Console.WriteLine(GetQuarterFromDate(new DateTime(2022, 2, 14))); 19 | Console.WriteLine(GetQuarterFromDate(new DateTime(2022, 7, 19))); 20 | Console.WriteLine(GetQuarterFromDate(new DateTime(2022, 12, 25))); 21 | Console.WriteLine(GetQuarterFromDate(new DateTime(2022, 4, 1))); 22 | 23 | // This also works with the regular "is" statement 24 | void FirstOrSecondHalf(object dt) { 25 | // TODO: Categorize the date into a half 26 | if (dt is DateTime {Month: > 6}) { 27 | Console.WriteLine("Date is in second half of the year"); 28 | } 29 | else if (dt is DateTime {Month: <= 6}) { 30 | Console.WriteLine("Date is in first half of the year"); 31 | } 32 | } 33 | FirstOrSecondHalf(new DateTime(2022, 7, 28)); 34 | FirstOrSecondHalf(new DateTime(2022, 4, 1)); 35 | -------------------------------------------------------------------------------- /Start/Events/BasicEvents/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programmin by Joe Marini 2 | // Example file for basic events 3 | 4 | namespace BasicEvents 5 | { 6 | // define the delegate for the event handler 7 | public delegate void MyEventHandler(string value); 8 | 9 | class EventPublisher { 10 | private string TheVal = ""; 11 | 12 | // TODO: declare the event 13 | 14 | public string Val { 15 | set { 16 | this.TheVal = value; 17 | // TODO: when the value changes, fire the event 18 | 19 | } 20 | } 21 | } 22 | 23 | class Program { 24 | static void Main(string[] args) { 25 | EventPublisher obj = new EventPublisher(); 26 | // TODO: use a named function as an event handler 27 | 28 | // TODO: use an anonymous delegate as an event handler 29 | 30 | 31 | string? str = ""; 32 | do { 33 | Console.WriteLine("Enter a value: "); 34 | str = Console.ReadLine(); 35 | if (!str!.Equals("exit")) { 36 | obj.Val = str; 37 | } 38 | } while (!str.Equals("exit")); 39 | Console.WriteLine("Goodbye!"); 40 | } 41 | 42 | // This function will be called when the value changes in the EventPublisher class 43 | static void ObjValueChanged(string value) { 44 | Console.WriteLine("The value changed to {0}", value); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Start/Delegates/ComposableDelegates/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Example file for composable delegates 3 | 4 | 5 | namespace Composable 6 | { 7 | // declare the delegate type 8 | public delegate void MyDelegate(int arg1, int arg2); 9 | 10 | class Program 11 | { 12 | static void func1(int arg1, int arg2) 13 | { 14 | string result = (arg1 + arg2).ToString(); 15 | Console.WriteLine("The number from func1 is: " + result); 16 | } 17 | 18 | static void func2(int arg1, int arg2) 19 | { 20 | string result = (arg1 * arg2).ToString(); 21 | Console.WriteLine("The number from func2 is: " + result); 22 | } 23 | 24 | static void Main(string[] args) 25 | { 26 | MyDelegate f1 = func1; 27 | MyDelegate f2 = func2; 28 | // Create a composed delegate from f1 and f2 29 | 30 | int a=10; 31 | int b=20; 32 | 33 | // call each delegate and then the chain 34 | Console.WriteLine("Calling the first delegate"); 35 | f1(a, b); 36 | Console.WriteLine("Calling the second delegate"); 37 | f2(a, b); 38 | // TODO: Call the composed delegate 39 | Console.WriteLine("\nCalling the chained delegates"); 40 | 41 | 42 | // TODO: subtract off one of the delegates 43 | Console.WriteLine("\nCalling the unchained delegates"); 44 | 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Start/PatternMatching/PositionalPatterns/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Using Positional and Tuple Patterns in Pattern Matching 3 | 4 | decimal GetGroupTicketPriceDiscount(int groupSize, DateTime visitDate) 5 | => (groupSize, visitDate.DayOfWeek) switch 6 | { 7 | // TODO: use the position of each value as an individual pattern expression 8 | 9 | _ => 0.0m, 10 | }; 11 | 12 | // Declare some test data to use with the example 13 | (int, DateTime)[] TestDiscountData = new[] { 14 | (4, new DateTime(2028, 9, 9)), 15 | (7, new DateTime(2028, 2, 7)), 16 | (20, new DateTime(2028, 4, 17)), 17 | (15, new DateTime(2028, 8, 8)), 18 | (9, new DateTime(2028, 8, 9)), 19 | }; 20 | 21 | // TODO: Iterate over each of the test data items and evaluate the discount 22 | 23 | 24 | // TODO: Use the implicit Deconstruct call to switch on the different values of a class 25 | 26 | 27 | // Declare some test data to use with the point example 28 | Point[] TestPointData = new[] { 29 | new Point(5, 8), 30 | new Point(-2, 7), 31 | new Point(1, -1), 32 | new Point(-2, -2), 33 | }; 34 | 35 | // foreach (Point p in TestPointData) { 36 | // Console.WriteLine($"Point is {Classify(p)}"); 37 | // } 38 | 39 | // Define a type that implements the Deconstruct method to return a tuple 40 | public readonly struct Point 41 | { 42 | public int X { get; } 43 | public int Y { get; } 44 | 45 | public Point(int x, int y) => (X, Y) = (x, y); 46 | 47 | public void Deconstruct(out int x, out int y) => (x, y) = (X, Y); 48 | } 49 | -------------------------------------------------------------------------------- /Start/PatternMatching/BasicPatterns/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // C# Pattern Matching for type testing 3 | #pragma warning disable CS8321 4 | 5 | // a very common use for pattern matching is to compare values, such as checking for null 6 | // The "is" expression is used for this to test the Constant pattern 7 | string? str = null; 8 | 9 | 10 | // The "is" expression can also be used to extract a value if one is present 11 | // This is called the Declaration pattern 12 | void DashedLine(object o) { 13 | // The old way of doing this is to try determine the type of the argument 14 | int l = 0; 15 | if (o.GetType() == typeof(int)) { 16 | l = (int)o; 17 | } 18 | string s; 19 | if (o.GetType() == typeof(string)) { 20 | s = (string)o; 21 | if (!int.TryParse(s, out l)) { 22 | l = 0; 23 | } 24 | } 25 | if (l > 0) { 26 | string str = new string('-', l); 27 | Console.WriteLine(str); 28 | } 29 | 30 | // The new way is to just use the declaration pattern 31 | 32 | } 33 | 34 | // Property pattern examines the properties of an object 35 | bool IsTheIdesOfMarch(DateTime date) { 36 | // Test the month and day properties 37 | return false; 38 | } 39 | 40 | // Console.WriteLine(IsTheIdesOfMarch(new DateTime(DateTime.Today.Year, 1, 13))); 41 | // Console.WriteLine(IsTheIdesOfMarch(new DateTime(DateTime.Today.Year, 3, 14))); 42 | // Console.WriteLine(IsTheIdesOfMarch(new DateTime(DateTime.Today.Year, 3, 15))); 43 | // Console.WriteLine(IsTheIdesOfMarch(new DateTime(DateTime.Today.Year, 3, 16))); 44 | -------------------------------------------------------------------------------- /Finished/Lambdas/LambdaDelegates/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Example file for lambdas as delegates 3 | 4 | namespace LambdaDelegates 5 | { 6 | // define a delegate 7 | public delegate void myEventHandler(string value); 8 | 9 | class MyClass 10 | { 11 | private string? theVal = null; 12 | public event myEventHandler? valueChanged; // no need to initialize to null, defaults to null 13 | 14 | public string Val 15 | { 16 | set 17 | { 18 | this.theVal = value; 19 | // when the value changes, fire the event 20 | this.valueChanged?.Invoke(theVal); // safe invocation 21 | } 22 | } 23 | } 24 | 25 | class Program 26 | { 27 | static void Main(string[] args) 28 | { 29 | MyClass obj = new MyClass(); 30 | 31 | // Use a Lambda expression to define an event handler 32 | // Note that this is a statement lambda, due to use of { } 33 | obj.valueChanged += (x) => { 34 | Console.WriteLine("The value changed to {0}", x); 35 | }; 36 | 37 | string? str; 38 | do 39 | { 40 | Console.WriteLine("Enter a value, or 'exit' to exit:"); 41 | str = Console.ReadLine(); 42 | if (!str!.Equals("exit")) 43 | { 44 | obj.Val = str; 45 | } 46 | } while (!str.Equals("exit")); 47 | 48 | Console.WriteLine("Goodbye!"); 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /Finished/Language/Indexers/StockRecord.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Example file for using class indexers 3 | 4 | // StockRecord is a sample class that returns information about 5 | // a week's worth of stock information - closing prices, etc. 6 | public class StockRecord { 7 | public string Symbol { 8 | get => "ABCD"; 9 | } 10 | 11 | private decimal[] prices = new decimal[] { 12 | 105.1m, 103.12m, 106.93m, 104.5m, 103.7m 13 | }; 14 | 15 | // Define some public properties 16 | public decimal Average { 17 | get => prices.Sum() / prices.Length; 18 | } 19 | public decimal High { 20 | get => prices.Max(); 21 | } 22 | public decimal Low { 23 | get => prices.Min(); 24 | } 25 | 26 | // TODO: implement Length property 27 | public int Length => prices.Length; 28 | 29 | // TODO: implement this[] to enable indexing 30 | public decimal this[int index] { 31 | get => prices[index]; 32 | } 33 | // TODO: You can overload the indexer to provide another way to access 34 | public decimal this [string day] { 35 | get { 36 | if (day == "mon") { 37 | return prices[0]; 38 | } 39 | if (day == "tue") { 40 | return prices[1]; 41 | } 42 | if (day == "wed") { 43 | return prices[2]; 44 | } 45 | if (day == "thu") { 46 | return prices[3]; 47 | } 48 | if (day == "fri") { 49 | return prices[4]; 50 | } 51 | throw new IndexOutOfRangeException($"'{day}' is not a valid index to StockRecord"); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Finished/Interfaces/MultipleInterfaces/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Example file for multiple interfaces 3 | 4 | namespace MultipleInterfaces 5 | { 6 | interface IStorable 7 | { 8 | void Save(); 9 | void Load(); 10 | Boolean NeedsSave { get; set; } 11 | } 12 | interface IEncryptable 13 | { 14 | void Encrypt(); 15 | void Decrypt(); 16 | } 17 | 18 | // Implement both interfaces 19 | class Document : IStorable, IEncryptable 20 | { 21 | private string name; 22 | private Boolean mNeedsSave = false; 23 | 24 | public Document(string s) { 25 | name = s; 26 | Console.WriteLine("Created a document with name '{0}'", s); 27 | } 28 | 29 | public void Save() { 30 | Console.WriteLine("Saving the document"); 31 | } 32 | 33 | public void Load() { 34 | Console.WriteLine("Loading the document"); 35 | } 36 | 37 | // Implement IEncryptable 38 | public void Encrypt() { 39 | Console.WriteLine("Encrypting the document"); 40 | } 41 | 42 | public void Decrypt() { 43 | Console.WriteLine("Decrypting the document"); 44 | } 45 | 46 | public Boolean NeedsSave { 47 | get { return mNeedsSave; } 48 | set { mNeedsSave = value; } 49 | } 50 | } 51 | 52 | class Program 53 | { 54 | static void Main(string[] args) { 55 | Document d = new Document("Test Document"); 56 | 57 | // Exercise the interfaces 58 | d.Load(); 59 | d.Encrypt(); 60 | d.Save(); 61 | d.Decrypt(); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Finished/Events/BasicEvents/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Example file for basic events 3 | 4 | namespace BasicEvents 5 | { 6 | // define the delegate for the event handler 7 | public delegate void MyEventHandler(string value); 8 | 9 | class EventPublisher 10 | { 11 | private string TheVal = ""; 12 | 13 | // declare the event 14 | public event MyEventHandler ValueChanged; 15 | 16 | public string Val 17 | { 18 | set 19 | { 20 | this.TheVal = value; 21 | // when the value changes, fire the event 22 | this.ValueChanged(TheVal); 23 | } 24 | } 25 | } 26 | 27 | class Program 28 | { 29 | static void Main(string[] args) 30 | { 31 | // use a named function as an event handler 32 | EventPublisher obj = new EventPublisher(); 33 | obj.ValueChanged += new MyEventHandler(ObjValueChanged); 34 | 35 | // use an anonymous delegate as an event handler 36 | obj.ValueChanged += delegate(string val) { 37 | Console.WriteLine("The value changed to {0}", val); 38 | }; 39 | 40 | string? str = ""; 41 | do { 42 | Console.WriteLine("Enter a value: "); 43 | str = Console.ReadLine(); 44 | if (!str!.Equals("exit")) { 45 | obj.Val = str; 46 | } 47 | } while (!str.Equals("exit")); 48 | Console.WriteLine("Goodbye!"); 49 | } 50 | 51 | static void ObjValueChanged(string value) 52 | { 53 | Console.WriteLine("The value changed to {0}", value); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Finished/PatternMatching/SwitchExpr/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // C# Pattern Matching using enhanced switch expressions 3 | 4 | // switch statements are very common in C#: 5 | string NumToString(int num) { 6 | switch (num) { 7 | case 1: 8 | return "One"; 9 | case 2: 10 | return "Two"; 11 | case 3: 12 | return "Three"; 13 | default: 14 | return "Unknown"; 15 | } 16 | } 17 | Console.WriteLine(NumToString(2)); 18 | Console.WriteLine(NumToString(4)); 19 | 20 | // switch statements can operate on just about any type 21 | string ShapeToString(object shape) { 22 | switch (shape) { 23 | case Circle: 24 | return "Circle"; 25 | case Rectangle: 26 | return "Rectangle"; 27 | case Triangle: 28 | return "Triangle"; 29 | default: 30 | return "Unknown"; 31 | } 32 | } 33 | Console.WriteLine(ShapeToString(new Circle {Radius = 10})); 34 | Console.WriteLine(ShapeToString(new Rectangle {Length = 5, Width = 10})); 35 | 36 | // This can be made a little more concise with the switch expression 37 | string ShapeToString2 (object shape) => shape switch { 38 | Circle {Radius: var r} when r > 10 => "Big Circle", 39 | Circle {Radius: var r} when r <= 10 => "Little Circle", 40 | Rectangle {Length: var l, Width: var w} when l == w => "Square", 41 | Rectangle => "Rectangle", 42 | Triangle => "Triangle", 43 | _ => "Unknown" 44 | }; 45 | Console.WriteLine(ShapeToString2(new Circle {Radius = 20})); 46 | Console.WriteLine(ShapeToString2(new Circle {Radius = 10})); 47 | Console.WriteLine(ShapeToString2(new Rectangle {Length = 10, Width = 10})); 48 | Console.WriteLine(ShapeToString2(new Rectangle {Length = 5, Width = 10})); 49 | -------------------------------------------------------------------------------- /Start/Interfaces/NETInterfaces/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Example file for built-in .NET interfaces 3 | 4 | // TODO: Include the namespace that contains INotifyPropertyChanged 5 | 6 | namespace NETInterfaces 7 | { 8 | interface IStorable 9 | { 10 | void Save(); 11 | void Load(); 12 | Boolean NeedsSave { get; set; } 13 | } 14 | 15 | // TODO: Implement INotifyPropertyChanged 16 | class Document : IStorable 17 | { 18 | private string name; 19 | private Boolean mNeedsSave = false; 20 | 21 | // TODO: INotifyPropertyChanged requires the implementation of 1 event 22 | 23 | // TODO: Define a utility function to call the PropertyChanged event 24 | 25 | public Document(string s) { 26 | name = s; 27 | Console.WriteLine("Created a document with name '{0}'", s); 28 | } 29 | 30 | public string DocName { 31 | get { return name; } 32 | set { 33 | name = value; 34 | } 35 | } 36 | 37 | public void Save() { 38 | Console.WriteLine("Saving the document"); 39 | } 40 | 41 | public void Load() { 42 | Console.WriteLine("Loading the document"); 43 | } 44 | 45 | public Boolean NeedsSave { 46 | get { return mNeedsSave; } 47 | set { 48 | mNeedsSave = value; 49 | } 50 | } 51 | } 52 | 53 | class Program 54 | { 55 | static void Main(string[] args) { 56 | Document d = new Document("Test Document"); 57 | 58 | // TODO: implement a delegate to handle the PropertyChanged event 59 | 60 | // Change a couple properties to trigger the event 61 | d.DocName = "My Document"; 62 | d.NeedsSave = true; 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Finished/PatternMatching/BasicPatterns/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // C# Pattern Matching for type testing 3 | 4 | // a very common use for pattern matching is to compare values, such as checking for null 5 | // The "is" expression is used for this to test the Constant pattern 6 | string? str = "This is a string"; 7 | 8 | if (str is not null) { 9 | Console.WriteLine($"The value of str is '{str}'"); 10 | } 11 | else { 12 | Console.WriteLine("str is null"); 13 | } 14 | 15 | // The "is" expression can also be used to extract a value if one is present 16 | // This is called the Declaration pattern 17 | void DashedLine(object o) { 18 | // The old way of doing this is to try determine the type of the argument 19 | // int l = 0; 20 | // if (o.GetType() == typeof(int)) { 21 | // l = (int)o; 22 | // } 23 | // string s; 24 | // if (o.GetType() == typeof(string)) { 25 | // s = (string)o; 26 | // if (!int.TryParse(s, out l)) { 27 | // l = 0; 28 | // } 29 | // } 30 | // if (l > 0) { 31 | // string str = new string('-', l); 32 | // Console.WriteLine(str); 33 | // } 34 | 35 | // The new way is to just use the declaration pattern 36 | if (o is int l || (o is string s && int.TryParse(s, out l))) { 37 | string str = new string('-', l); 38 | Console.WriteLine(str); 39 | } 40 | } 41 | 42 | DashedLine(25); 43 | DashedLine("50"); 44 | DashedLine(20.5); 45 | 46 | // Property pattern examines the properties of an object 47 | bool IsTheIdesOfMarch(DateTime date) { 48 | // Test the month and day properties 49 | return (date is {Month: 3, Day: 14 or 15}); 50 | } 51 | Console.WriteLine(IsTheIdesOfMarch(new DateTime(DateTime.Today.Year, 1, 13))); 52 | Console.WriteLine(IsTheIdesOfMarch(new DateTime(DateTime.Today.Year, 3, 14))); 53 | Console.WriteLine(IsTheIdesOfMarch(new DateTime(DateTime.Today.Year, 3, 15))); 54 | Console.WriteLine(IsTheIdesOfMarch(new DateTime(DateTime.Today.Year, 3, 16))); 55 | -------------------------------------------------------------------------------- /Start/Events/ChainedEvents/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programmin by Joe Marini 2 | // Example file for chained events 3 | 4 | namespace ChainedEvents 5 | { 6 | // define the delegate for the event handler 7 | public delegate void MyEventHandler(string value); 8 | 9 | class EventPublisher 10 | { 11 | private string TheVal; 12 | // declare the event handler 13 | public event MyEventHandler ValueChanged; 14 | // TODO4: Use the EventArgs class 15 | 16 | 17 | public string Val 18 | { 19 | set { 20 | this.TheVal = value; 21 | // when the value changes, fire the event 22 | this.ValueChanged(TheVal); 23 | // TODO5: Use the custom event handler 24 | 25 | } 26 | } 27 | } 28 | 29 | // TODO3: Create a subclass of EventArgs for our use 30 | 31 | class Program 32 | { 33 | static void Main(string[] args) 34 | { 35 | // create the test class 36 | EventPublisher obj = new EventPublisher(); 37 | // TODO1: Connect multiple event handlers 38 | 39 | 40 | // TODO2: Use an anonymous delegate as the event handler 41 | 42 | 43 | // TODO6: Listen for the custom event we defined with EventArgs 44 | 45 | 46 | string str; 47 | do { 48 | Console.WriteLine("Enter a value: "); 49 | str = Console.ReadLine(); 50 | if (!str.Equals("exit")) { 51 | obj.Val = str; 52 | } 53 | } while (!str.Equals("exit")); 54 | Console.WriteLine("Goodbye!"); 55 | } 56 | 57 | static void changeListener1(string value) 58 | { 59 | Console.WriteLine("The value changed to {0}", value); 60 | } 61 | static void changeListener2(string value) 62 | { 63 | Console.WriteLine("I also listen to the event, and got {0}", value); 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /Finished/PatternMatching/PositionalPatterns/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Using Positional and Tuple Patterns in Pattern Matching 3 | 4 | decimal GetGroupTicketPriceDiscount(int groupSize, DateTime visitDate) 5 | => (groupSize, visitDate.DayOfWeek) switch 6 | { 7 | // use the position of each value as an individual pattern expression 8 | (<= 0, _) => throw new ArgumentException("Group size must be a positive number"), 9 | (_, DayOfWeek.Saturday or DayOfWeek.Sunday) => 0.0m, 10 | (>= 5 and < 10, DayOfWeek.Monday) => 0.2m, 11 | (>= 10, DayOfWeek.Monday) => 0.3m, 12 | (>= 5 and < 10, _) => 0.12m, 13 | (>= 10, _) => 0.15m, 14 | _ => 0.0m, 15 | }; 16 | 17 | // Declare some test data to use with the example 18 | (int, DateTime)[] TestDiscountData = new[] { 19 | (4, new DateTime(2022, 9, 3)), 20 | (7, new DateTime(2023, 2, 6)), 21 | (20, new DateTime(2023, 4, 17)), 22 | (15, new DateTime(2023, 8, 8)), 23 | (9, new DateTime(2023, 8, 9)), 24 | }; 25 | 26 | // Iterate over each of the test data items and evaluate the discount 27 | foreach ((var size, var date) in TestDiscountData) { 28 | decimal discount = GetGroupTicketPriceDiscount(size, date); 29 | Console.WriteLine($"The discount for a {size}-person group on {date:ddd, MMM d} is {discount}"); 30 | } 31 | 32 | // Use the implicit Deconstruct call to switch on the different values of a class 33 | string Classify(Point point) => point switch 34 | { 35 | (> 0, > 0) => "Upper right quadrant", 36 | (< 0, > 0) => "Upper left quadrant", 37 | (> 0, < 0) => "Lower right quadrant", 38 | (< 0, < 0) => "Lower left quadrant", 39 | _ => "Just a point", 40 | }; 41 | 42 | // Declare some test data to use with the point example 43 | Point[] TestPointData = new[] { 44 | new Point(5, 8), 45 | new Point(-2, 7), 46 | new Point(1, -1), 47 | new Point(-2, -2), 48 | }; 49 | 50 | foreach (Point p in TestPointData) { 51 | Console.WriteLine($"Point is {Classify(p)}"); 52 | } 53 | 54 | // Define a type that implements the Deconstruct method to return a tuple 55 | public readonly struct Point 56 | { 57 | public int X { get; } 58 | public int Y { get; } 59 | 60 | public Point(int x, int y) => (X, Y) = (x, y); 61 | 62 | public void Deconstruct(out int x, out int y) => (x, y) = (X, Y); 63 | } 64 | -------------------------------------------------------------------------------- /Finished/Interfaces/NETInterfaces/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Example file for built-in .NET interfaces 3 | 4 | // Include the namespace that contains INotifyPropertyChanged 5 | using System.ComponentModel; 6 | 7 | namespace NETInterfaces 8 | { 9 | interface IStorable 10 | { 11 | void Save(); 12 | void Load(); 13 | Boolean NeedsSave { get; set; } 14 | } 15 | 16 | class Document : IStorable, INotifyPropertyChanged 17 | { 18 | private string name; 19 | private Boolean mNeedsSave = false; 20 | 21 | // INotifyPropertyChanged requires the implementation of 1 event 22 | public event PropertyChangedEventHandler PropertyChanged; 23 | 24 | // Define a utility function to call the PropertyChanged event 25 | private void NotifyPropChanged(string propName) { 26 | PropertyChanged(this, new PropertyChangedEventArgs(propName)); 27 | } 28 | 29 | public Document(string s) { 30 | name = s; 31 | Console.WriteLine("Created a document with name '{0}'", s); 32 | } 33 | 34 | public string DocName { 35 | get { return name; } 36 | set { 37 | name = value; 38 | NotifyPropChanged("DocName"); 39 | } 40 | } 41 | 42 | public void Save() { 43 | Console.WriteLine("Saving the document"); 44 | } 45 | 46 | public void Load() { 47 | Console.WriteLine("Loading the document"); 48 | } 49 | 50 | public Boolean NeedsSave { 51 | get { return mNeedsSave; } 52 | set { 53 | mNeedsSave = value; 54 | NotifyPropChanged("NeedsSave"); 55 | } 56 | } 57 | } 58 | 59 | class Program 60 | { 61 | static void Main(string[] args) { 62 | Document d = new Document("Test Document"); 63 | 64 | // implement a delegate to handle the PropertyChanged event 65 | d.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e) { 66 | Console.WriteLine("Document property changed: {0}", e.PropertyName); 67 | }; 68 | 69 | // Change a couple properties to trigger the event 70 | d.DocName = "My Document"; 71 | d.NeedsSave = true; 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Finished/Events/ChainedEvents/Program.cs: -------------------------------------------------------------------------------- 1 | // LinkedIn Learning Course exercise file for Advanced C# Programming by Joe Marini 2 | // Example file for chained events 3 | 4 | namespace ChainedEvents 5 | { 6 | // define the delegate for the event handler 7 | public delegate void MyEventHandler(string value); 8 | 9 | class MyClass 10 | { 11 | private string TheVal; 12 | // declare the event handler 13 | public event MyEventHandler ValueChanged; 14 | public event EventHandler ObjChanged; 15 | 16 | public string Val 17 | { 18 | set 19 | { 20 | this.TheVal = value; 21 | // when the value changes, fire the event 22 | this.ValueChanged(TheVal); 23 | this.ObjChanged(this, new ObjChangeEventArgs() { PropChanged = "Val" }); 24 | } 25 | } 26 | } 27 | 28 | class ObjChangeEventArgs : EventArgs 29 | { 30 | public string PropChanged; 31 | } 32 | 33 | class Program 34 | { 35 | static void Main(string[] args) 36 | { 37 | // create the test class 38 | MyClass obj = new MyClass(); 39 | // Connect multiple event handlers 40 | obj.ValueChanged += new MyEventHandler(ChangeListener1); 41 | obj.ValueChanged += new MyEventHandler(ChangeListener2); 42 | 43 | // Use an anonymous delegate as the event handler 44 | obj.ValueChanged += delegate(string s) { 45 | Console.WriteLine("This came from the anonymous handler!"); 46 | }; 47 | 48 | obj.ObjChanged += delegate(object sender, ObjChangeEventArgs e) { 49 | Console.WriteLine("{0} had the '{1}' property changed", sender.GetType(), e.PropChanged); 50 | }; 51 | 52 | string str; 53 | do { 54 | Console.WriteLine("Enter a value: "); 55 | str = Console.ReadLine(); 56 | if (!str.Equals("exit")) { 57 | obj.Val = str; 58 | } 59 | } while (!str.Equals("exit")); 60 | Console.WriteLine("Goodbye!"); 61 | } 62 | 63 | static void ChangeListener1(string value) 64 | { 65 | Console.WriteLine("The value changed to {0}", value); 66 | } 67 | static void ChangeListener2(string value) 68 | { 69 | Console.WriteLine("I also listen to the event, and got {0}", value); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Advanced C# Programming Concepts 2 | This is the repository for the LinkedIn Learning course `Advanced C# Programming Concepts`. The full course is available from [LinkedIn Learning][lil-course-url]. 3 | 4 | ![lil-thumbnail-url] 5 | 6 | ## Course Description 7 | 8 |

Explore modern language features and development patterns in this advanced skills course on C#. Instructor Joe Marini guides you through sophisticated programming techniques including C# indexers, pattern matching, and improved syntax for enhanced code readability. In addition, he covers critical topics such as delegates, events, lambda expressions, and interfaces, equipping you with comprehensive skills for creating more flexible and efficient code. Through practical examples, you’ll get a chance to master custom type manipulation and advanced object-oriented programming concepts like deconstruction syntax, null-coalescing operators, and custom type comparisons.

This course is integrated with GitHub Codespaces, an instant cloud developer environment that offers all the functionality of your favorite IDE without the need for any local machine setup. With GitHub Codespaces, you can get hands-on practice from any machine, at any time—all while using a tool that you’ll likely encounter in the workplace. Check out “Using GitHub Codespaces" with this course to learn how to get started.

This course also includes Code Challenges powered by CoderPad. Code Challenges are interactive coding exercises with real-time feedback, so you can get hands-on coding practice alongside the course content to advance your programming skills.

9 | 10 | ## Instructor 11 | 12 | As a technology industry veteran, Joe Marini has held multiple roles in engineering, product management, and leadership. 13 | 14 | Joe Marini has more than 35 years of experience in the technology industry, and has authored several books and more than 40 educational courses on software development. He has held prominent roles at several Silicon Valley companies including Adobe, Microsoft, Google, and Databricks. 15 | 16 | 17 | Check out my other courses on [LinkedIn Learning](https://www.linkedin.com/learning/instructors/joe-marini). 18 | 19 | 20 | [0]: # (Replace these placeholder URLs with actual course URLs) 21 | 22 | [lil-course-url]: https://www.linkedin.com/learning/advanced-c-sharp-programming-concepts 23 | [lil-thumbnail-url]: https://media.licdn.com/dms/image/v2/D4E0DAQEAwibW5-phug/learning-public-crop_675_1200/B4EZdCHJEiHQAk-/0/1749160858554?e=2147483647&v=beta&t=Z2_SIdNFNvT28MoXjnWKAxG-0xtnYZPzI0gZXY1n6V4 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Apple 2 | *.DS_Store 3 | 4 | # Built application files 5 | *.apk 6 | *.ap_ 7 | 8 | # Files for the Dalvik VM 9 | *.dex 10 | 11 | # Java class files 12 | *.class 13 | 14 | # Generated files 15 | bin/ 16 | gen/ 17 | 18 | # Gradle files 19 | .gradle/ 20 | build/ 21 | 22 | # Local configuration file (sdk path, etc) 23 | local.properties 24 | 25 | # Proguard folder generated by Eclipse 26 | proguard/ 27 | 28 | # Log Files 29 | *.log 30 | 31 | # Android Studio Navigation editor temp files 32 | .navigation/ 33 | 34 | # Android Studio captures folder 35 | captures/ 36 | 37 | # Google Doc files 38 | *.gsheet 39 | *.gslides 40 | *.gdoc 41 | 42 | # MS Office files 43 | *.xls_ 44 | *.doc_ 45 | *.ppt_ 46 | 47 | # PDF files 48 | *.pdf 49 | 50 | # ZIP files 51 | *.zip 52 | 53 | # VISUAL STUDIO FILES 54 | 55 | # User-specific files 56 | *.suo 57 | *.user 58 | *.userosscache 59 | *.sln.docstates 60 | 61 | # User-specific files (MonoDevelop/Xamarin Studio) 62 | *.userprefs 63 | 64 | # Build results 65 | [Dd]ebug/ 66 | [Dd]ebugPublic/ 67 | [Rr]elease/ 68 | [Rr]eleases/ 69 | x64/ 70 | x86/ 71 | bld/ 72 | [Bb]in/ 73 | [Oo]bj/ 74 | [Ll]og/ 75 | __pycache__/ 76 | 77 | # Visual Studio 2015 cache/options directory 78 | .vs/ 79 | # Uncomment if you have tasks that create the project's static files in wwwroot 80 | #wwwroot/ 81 | 82 | # MSTest test Results 83 | [Tt]est[Rr]esult*/ 84 | [Bb]uild[Ll]og.* 85 | 86 | # NUNIT 87 | *.VisualState.xml 88 | TestResult.xml 89 | 90 | # Build Results of an ATL Project 91 | [Dd]ebugPS/ 92 | [Rr]eleasePS/ 93 | dlldata.c 94 | 95 | # DNX 96 | project.lock.json 97 | artifacts/ 98 | 99 | *_i.c 100 | *_p.c 101 | *_i.h 102 | *.ilk 103 | *.meta 104 | *.obj 105 | *.pch 106 | *.pdb 107 | *.pgc 108 | *.pgd 109 | *.rsp 110 | *.sbr 111 | *.tlb 112 | *.tli 113 | *.tlh 114 | *.tmp 115 | *.tmp_proj 116 | *.log 117 | *.vspscc 118 | *.vssscc 119 | .builds 120 | *.pidb 121 | *.svclog 122 | *.scc 123 | 124 | # Chutzpah Test files 125 | _Chutzpah* 126 | 127 | # Visual C++ cache files 128 | ipch/ 129 | *.aps 130 | *.ncb 131 | *.opendb 132 | *.opensdf 133 | *.sdf 134 | *.cachefile 135 | *.VC.db 136 | *.VC.VC.opendb 137 | 138 | # Visual Studio profiler 139 | *.psess 140 | *.vsp 141 | *.vspx 142 | *.sap 143 | 144 | # TFS 2012 Local Workspace 145 | $tf/ 146 | 147 | # Guidance Automation Toolkit 148 | *.gpState 149 | 150 | # ReSharper is a .NET coding add-in 151 | _ReSharper*/ 152 | *.[Rr]e[Ss]harper 153 | *.DotSettings.user 154 | 155 | # JustCode is a .NET coding add-in 156 | .JustCode 157 | 158 | # TeamCity is a build add-in 159 | _TeamCity* 160 | 161 | # DotCover is a Code Coverage Tool 162 | *.dotCover 163 | 164 | # NCrunch 165 | _NCrunch_* 166 | .*crunch*.local.xml 167 | nCrunchTemp_* 168 | 169 | # MightyMoose 170 | *.mm.* 171 | AutoTest.Net/ 172 | 173 | # Web workbench (sass) 174 | .sass-cache/ 175 | 176 | # Installshield output folder 177 | [Ee]xpress/ 178 | 179 | # DocProject is a documentation generator add-in 180 | DocProject/buildhelp/ 181 | DocProject/Help/*.HxT 182 | DocProject/Help/*.HxC 183 | DocProject/Help/*.hhc 184 | DocProject/Help/*.hhk 185 | DocProject/Help/*.hhp 186 | DocProject/Help/Html2 187 | DocProject/Help/html 188 | 189 | # Click-Once directory 190 | publish/ 191 | 192 | # Publish Web Output 193 | *.[Pp]ublish.xml 194 | *.azurePubxml 195 | # TODO: Comment the next line if you want to checkin your web deploy settings 196 | # but database connection strings (with potential passwords) will be unencrypted 197 | *.pubxml 198 | *.publishproj 199 | 200 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 201 | # checkin your Azure Web App publish settings, but sensitive information contained 202 | # in these scripts will be unencrypted 203 | PublishScripts/ 204 | 205 | # NuGet Packages 206 | *.nupkg 207 | # The packages folder can be ignored because of Package Restore 208 | **/packages/* 209 | # except build/, which is used as an MSBuild target. 210 | !**/packages/build/ 211 | # Uncomment if necessary however generally it will be regenerated when needed 212 | #!**/packages/repositories.config 213 | # NuGet v3's project.json files produces more ignoreable files 214 | *.nuget.props 215 | *.nuget.targets 216 | 217 | # Microsoft Azure Build Output 218 | csx/ 219 | *.build.csdef 220 | 221 | # Microsoft Azure Emulator 222 | ecf/ 223 | rcf/ 224 | 225 | # Windows Store app package directories and files 226 | AppPackages/ 227 | BundleArtifacts/ 228 | Package.StoreAssociation.xml 229 | _pkginfo.txt 230 | 231 | # Visual Studio cache files 232 | # files ending in .cache can be ignored 233 | *.[Cc]ache 234 | # but keep track of directories ending in .cache 235 | !*.[Cc]ache/ 236 | 237 | # Others 238 | ClientBin/ 239 | ~$* 240 | *~ 241 | *.dbmdl 242 | *.dbproj.schemaview 243 | *.pfx 244 | *.publishsettings 245 | node_modules/ 246 | orleans.codegen.cs 247 | 248 | # Since there are multiple workflows, uncomment next line to ignore bower_components 249 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 250 | #bower_components/ 251 | 252 | # RIA/Silverlight projects 253 | Generated_Code/ 254 | 255 | # Backup & report files from converting an old project file 256 | # to a newer Visual Studio version. Backup files are not needed, 257 | # because we have git ;-) 258 | _UpgradeReport_Files/ 259 | Backup*/ 260 | UpgradeLog*.XML 261 | UpgradeLog*.htm 262 | 263 | # SQL Server files 264 | *.mdf 265 | *.ldf 266 | 267 | # Business Intelligence projects 268 | *.rdl.data 269 | *.bim.layout 270 | *.bim_*.settings 271 | 272 | # Microsoft Fakes 273 | FakesAssemblies/ 274 | 275 | # GhostDoc plugin setting file 276 | *.GhostDoc.xml 277 | 278 | # Node.js Tools for Visual Studio 279 | .ntvs_analysis.dat 280 | 281 | # Visual Studio 6 build log 282 | *.plg 283 | 284 | # Visual Studio 6 workspace options file 285 | *.opt 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # JetBrains Rider 303 | .idea/ 304 | *.sln.iml 305 | 306 | # VS Code folder 307 | .vscode/ 308 | 309 | # Databricks file 310 | *.pyi 311 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | LinkedIn Learning Exercise Files License Agreement 2 | ================================================== 3 | 4 | This License Agreement (the "Agreement") is a binding legal agreement 5 | between you (as an individual or entity, as applicable) and LinkedIn 6 | Corporation (“LinkedIn”). By downloading or using the LinkedIn Learning 7 | exercise files in this repository (“Licensed Materials”), you agree to 8 | be bound by the terms of this Agreement. If you do not agree to these 9 | terms, do not download or use the Licensed Materials. 10 | 11 | 1. License. 12 | - a. Subject to the terms of this Agreement, LinkedIn hereby grants LinkedIn 13 | members during their LinkedIn Learning subscription a non-exclusive, 14 | non-transferable copyright license, for internal use only, to 1) make a 15 | reasonable number of copies of the Licensed Materials, and 2) make 16 | derivative works of the Licensed Materials for the sole purpose of 17 | practicing skills taught in LinkedIn Learning courses. 18 | - b. Distribution. Unless otherwise noted in the Licensed Materials, subject 19 | to the terms of this Agreement, LinkedIn hereby grants LinkedIn members 20 | with a LinkedIn Learning subscription a non-exclusive, non-transferable 21 | copyright license to distribute the Licensed Materials, except the 22 | Licensed Materials may not be included in any product or service (or 23 | otherwise used) to instruct or educate others. 24 | 25 | 2. Restrictions and Intellectual Property. 26 | - a. You may not to use, modify, copy, make derivative works of, publish, 27 | distribute, rent, lease, sell, sublicense, assign or otherwise transfer the 28 | Licensed Materials, except as expressly set forth above in Section 1. 29 | - b. Linkedin (and its licensors) retains its intellectual property rights 30 | in the Licensed Materials. Except as expressly set forth in Section 1, 31 | LinkedIn grants no licenses. 32 | - c. You indemnify LinkedIn and its licensors and affiliates for i) any 33 | alleged infringement or misappropriation of any intellectual property rights 34 | of any third party based on modifications you make to the Licensed Materials, 35 | ii) any claims arising from your use or distribution of all or part of the 36 | Licensed Materials and iii) a breach of this Agreement. You will defend, hold 37 | harmless, and indemnify LinkedIn and its affiliates (and our and their 38 | respective employees, shareholders, and directors) from any claim or action 39 | brought by a third party, including all damages, liabilities, costs and 40 | expenses, including reasonable attorneys’ fees, to the extent resulting from, 41 | alleged to have resulted from, or in connection with: (a) your breach of your 42 | obligations herein; or (b) your use or distribution of any Licensed Materials. 43 | 44 | 3. Open source. This code may include open source software, which may be 45 | subject to other license terms as provided in the files. 46 | 47 | 4. Warranty Disclaimer. LINKEDIN PROVIDES THE LICENSED MATERIALS ON AN “AS IS” 48 | AND “AS AVAILABLE” BASIS. LINKEDIN MAKES NO REPRESENTATION OR WARRANTY, 49 | WHETHER EXPRESS OR IMPLIED, ABOUT THE LICENSED MATERIALS, INCLUDING ANY 50 | REPRESENTATION THAT THE LICENSED MATERIALS WILL BE FREE OF ERRORS, BUGS OR 51 | INTERRUPTIONS, OR THAT THE LICENSED MATERIALS ARE ACCURATE, COMPLETE OR 52 | OTHERWISE VALID. TO THE FULLEST EXTENT PERMITTED BY LAW, LINKEDIN AND ITS 53 | AFFILIATES DISCLAIM ANY IMPLIED OR STATUTORY WARRANTY OR CONDITION, INCLUDING 54 | ANY IMPLIED WARRANTY OR CONDITION OF MERCHANTABILITY OR FITNESS FOR A 55 | PARTICULAR PURPOSE, AVAILABILITY, SECURITY, TITLE AND/OR NON-INFRINGEMENT. 56 | YOUR USE OF THE LICENSED MATERIALS IS AT YOUR OWN DISCRETION AND RISK, AND 57 | YOU WILL BE SOLELY RESPONSIBLE FOR ANY DAMAGE THAT RESULTS FROM USE OF THE 58 | LICENSED MATERIALS TO YOUR COMPUTER SYSTEM OR LOSS OF DATA. NO ADVICE OR 59 | INFORMATION, WHETHER ORAL OR WRITTEN, OBTAINED BY YOU FROM US OR THROUGH OR 60 | FROM THE LICENSED MATERIALS WILL CREATE ANY WARRANTY OR CONDITION NOT 61 | EXPRESSLY STATED IN THESE TERMS. 62 | 63 | 5. Limitation of Liability. LINKEDIN SHALL NOT BE LIABLE FOR ANY INDIRECT, 64 | INCIDENTAL, SPECIAL, PUNITIVE, CONSEQUENTIAL OR EXEMPLARY DAMAGES, INCLUDING 65 | BUT NOT LIMITED TO, DAMAGES FOR LOSS OF PROFITS, GOODWILL, USE, DATA OR OTHER 66 | INTANGIBLE LOSSES . IN NO EVENT WILL LINKEDIN'S AGGREGATE LIABILITY TO YOU 67 | EXCEED $100. THIS LIMITATION OF LIABILITY SHALL: 68 | - i. APPLY REGARDLESS OF WHETHER (A) YOU BASE YOUR CLAIM ON CONTRACT, TORT, 69 | STATUTE, OR ANY OTHER LEGAL THEORY, (B) WE KNEW OR SHOULD HAVE KNOWN ABOUT 70 | THE POSSIBILITY OF SUCH DAMAGES, OR (C) THE LIMITED REMEDIES PROVIDED IN THIS 71 | SECTION FAIL OF THEIR ESSENTIAL PURPOSE; AND 72 | - ii. NOT APPLY TO ANY DAMAGE THAT LINKEDIN MAY CAUSE YOU INTENTIONALLY OR 73 | KNOWINGLY IN VIOLATION OF THESE TERMS OR APPLICABLE LAW, OR AS OTHERWISE 74 | MANDATED BY APPLICABLE LAW THAT CANNOT BE DISCLAIMED IN THESE TERMS. 75 | 76 | 6. Termination. This Agreement automatically terminates upon your breach of 77 | this Agreement or termination of your LinkedIn Learning subscription. On 78 | termination, all licenses granted under this Agreement will terminate 79 | immediately and you will delete the Licensed Materials. Sections 2-7 of this 80 | Agreement survive any termination of this Agreement. LinkedIn may discontinue 81 | the availability of some or all of the Licensed Materials at any time for any 82 | reason. 83 | 84 | 7. Miscellaneous. This Agreement will be governed by and construed in 85 | accordance with the laws of the State of California without regard to conflict 86 | of laws principles. The exclusive forum for any disputes arising out of or 87 | relating to this Agreement shall be an appropriate federal or state court 88 | sitting in the County of Santa Clara, State of California. If LinkedIn does 89 | not act to enforce a breach of this Agreement, that does not mean that 90 | LinkedIn has waived its right to enforce this Agreement. The Agreement does 91 | not create a partnership, agency relationship, or joint venture between the 92 | parties. Neither party has the power or authority to bind the other or to 93 | create any obligation or responsibility on behalf of the other. You may not, 94 | without LinkedIn’s prior written consent, assign or delegate any rights or 95 | obligations under these terms, including in connection with a change of 96 | control. Any purported assignment and delegation shall be ineffective. The 97 | Agreement shall bind and inure to the benefit of the parties, their respective 98 | successors and permitted assigns. If any provision of the Agreement is 99 | unenforceable, that provision will be modified to render it enforceable to the 100 | extent possible to give effect to the parties’ intentions and the remaining 101 | provisions will not be affected. This Agreement is the only agreement between 102 | you and LinkedIn regarding the Licensed Materials, and supersedes all prior 103 | agreements relating to the Licensed Materials. 104 | 105 | Last Updated: March 2019 106 | --------------------------------------------------------------------------------