This repo is created to track and record learning C#
- Learn how to create a C# (.Net Framework) console app
- Learn about Console.Write, Console.WriteLine(), Console.ReadLine() methods
- Learn how to build and run C# app
- Learn about different types of variables (string, int, double, decimal, boolean)
- Learn to declare a variable
- Learn to use a variable
- Strings (Learn about escaping characters, string literal, string interpolation)
- Difference between double and decimal
- Identify when to use int and string
This app was created to implement learning from Module02Lesson02Variables and uses following C# features
- Use Console.Write to output message
- Use Console.ReadLine() to collect data from user and assign it to variable
- Use bool and while loop to collect age data from user
- Use int.TryParse() method to convert string into integer age
- Use Console.Clear() to clear console screen
- Learn about if / else if / else conditonal statements
- Learn about &&, ||, == operators
- Learn about switch statements
- Learn about .ToLower() method
- Practise if else conditional statements
- Console app to welcome Tim Corey as professor and others as students
- Convert string to int
- Learn how to use int.TryParse and int.Parse methods
- Combining int.TryParse methods with if/else conditions
- Console app asks for user age and calculates how old user was in the year 2000
- While loop is used to ensure correct age is entered by user
- if / else statement is used to display results
- Mini project to practise if/else conditon
- Convert string to int
- Perform subtraction operation on string interpolation
- Practise writing pseudocode
- While Loop (runs 0 or more times)
- Do while loop (runs 1 or more times)
- Looping is important to ensure user enters correct data or to perform any kind of validation
- Ask for the users name. If users name is Tim, say "Hello Professor" otherwise, say hi username until they type exit
- Do while loop is chosen as the code needs to run at least once
- If / else statemennt is used inside loop for conditional check
- Create Array
- Different ways of creating arrays
- Accessing array element
- Array length and indexing
- Console app to create an array with three names
- User selects number 1 to 3 and respective name is displayed based on first, second and third name in an array
- Learn how to use and access array
- how to create lists
- advantages of lists
- how to add data to lists
- how to remove elements from lists
- how to replace elements from lists
- Console app to add students until there are no more students to add
- uses while loop to check if user wants to add students or not
- uses while loop to collect correct data format
- adds student names to the list if the user wants to add student to list
- How to create key value pairs
- How to check if key is present
- How to access value of key
- Keys must be unique, if same then it will overwrite previous values
- Console app: Create a dictionary with id and name
- ask user for id and display the name
- check the id is correct, a number and is within range
- re-prompt user for id if id is incorrect
- How to use for loop
- How to increase and decrease for loop
- How to use for loops with arrays and lists
- Console App that asks username seperated by commas
- Regex set up to remove all whitespaces, tabs
- Split user input and assign it to an array
- Print the contents of array using for loop
- How to use forEach
- When to use forEach
- Use forEach as much as possible with lists, arrays
- Console App that asks firstname
- adds user input into list
- then displays the user input using foreach loop
- Learn how to use methods
- why methods are important
- Concept of DRY Do not repeat yourself
- Global variables
- How to create and call methods
- Console app to create two methods
- One method asks user for username
- Another method welcomes user by printing "Hello username"
- Create breakpoint by clicking the grey area
- Use locals to watch the existing variables
- Create breakpoints at different points
- Remove breakpoints by clicking on the breakpoint or Debug > Toggle Breakpoint
- How to handle exception using try and catch
- Try tries to execute a code
- catch catches and error and throws exception
- Different types of exception
- Use try catch
- Deal with advanced breakpoints
- Add conditions to breakpoints
- Add action and log to breakpoints
- import and export exceptions
- how to create static classes
- importance of public classes
- why static classes are important
- use class files to seperate code
- Create a console app with static class that handles calculations
- Create different classes
- Instantiate class
- Purpose of instantiating data
- Console app that has a person class and an address class
- Instantiate class
- Create class
- Use class in method
- Difference between auto prop and full prop
- Use full prop when data needs to be masked or filtered/checked
- As a default always use auto props
- Console app that has properties for street address, city, state and zip code
- Then add a FullAddress property that is read-only
- Importance of class library
- how to reference class library to user interface
- put as much code as possible into class library
- do not put user interface code to class library (for e.g. console.writeline and readline etc)
- Try to make a console app without looking at the tutorial
- Create a battleship console app
- Use all the concepts up to module04
- Follow tutorial and complete challenges
- Complete methods challenges
- Define inheritance (special class which can be passed down to other class)
- When to use inheritance (whenever property is a relationship inheritance should be used)
- When not to use inheritance (if a property does not apply we should not inherit it)
- Cannot inherit directly from more than one class
- Miniproject that uses inheritance and interface
- Interface can be used to connect non related items together
- Different types of modifiers and its usage
- How to create Abstract class
- How to create method overiding
- Excercise to practise overiding
- Mini project to implement abstract, access modifier, enums
- Method overload means having multiple methods with same name but different parameters
- Can have two methods with same name as long as their signatures are different
- Method overload allows us to have different configuration set up for a method
- method overload is ideal when
- performing same operation with different data types
- providing flexibility in input
- improving code readability and input
- What is a extension method ?
- Way to add additional functionality to an existing class without modifying its source code or creating a new derived class.
- Simple analogy: Shoes which is functional but you want it to be waterproof. Instead of creating shoes from scratch you can just add a waterproof spray. Waterproof spray is like an extension method.
- How to create an extension method ?
- step 1: Create a static class (helper container)
- step 2: Inside that static class create a static method. First parameter of method starts with "this" keyword
- step 3: Populate the method as required. Once complete method becomes and use it using dot notation (e.g. variable.ExtensionMethod())
- Why and When to use extension class ?
- When you don't have access to source code or you don't own class but you want to add functionality, e.g. extension method to add data to database
- To keep your code clean as you don't need to create subclasses or modify source code
- Make code more readable by calling methods directly on the objects they relate to
- Create the following chain using extension methods person.SetDefaultAge().PrintInfo()
- In this example default age has been set as 18 and provided as an optional parameter
- MiniProject to practise extension method and method overloading
- Practice extension method and method overloading without looking at solution
- What is a generic item ?
- Generic item allows us to define classes, methods, and data structures that can operate with any data type while maintaining type safety. So this works with any datatype we provide.
- Why do we need Generics ?
- We need generics to ensure type safetey i.e. ensure compile time type checking and prevent runtime errors
- It also allows us to write one method or class that works with any data type
- It also increases the performance as it avoids boxing/ unboxing for value types
- How do we create Generics ?
- We create generics by adding to class and methods
##Module06Lesson12GenericsDemoExcercise
- Excercise to practice Generics
##Module06Lesson13EventDemoApp
- What is an event Listener ?
- Event listener listens to changes in state and can reports back so we know state has changed. e.g. if we are loading a lot of data in the background and wanted to let the user know when done then we can use event listener.
- Why do we need event listener ?
- Whenever the state of object changes we will need event listener to notify the state has changed.
- How do we create an even listener
- There is three parts to event handlers.
- Declaration - must be done in class where the model will be invoked, syntax - public EventHandler EventHandlerName
- Listener - must be done in Main class, syntax - Object.EventHandlerName += EventHandler_Name
- Invokation - must be done inside method where it is to be triggered upon meeting certain condition, syntax EventHandlerName?Invoke(this, message)
- There is three parts to event handlers.
##Module06Lesson13EventDemoAppExcercise
- Create an event in a class and then consume that class. Attach a listener to the event and have it wire to the console
- Event listener created to notify user if stock ISA portfolio is greater than 20k.
##Module07Lesson04UnitTestDemoLibraryApp
- Unit test using XUnit
- Unit test tests is only intended to test one unit of work (i.e. one method)
- Unit test only tests public methods
- You should not test your dependencies, it must be independent of email, database, we just want to test the logic
- Use [Fact] if you only want to test once, if you want to run multiple tests use [Theory] and [InlineData(params)]
- Unit test should have these features
- Arrange: Instantiate a class
- Act: Call upon the method to be tested
- Assert: Compare the expected and actual
##Module07Lesson04UnitTestDemoLibraryExcerciseApp
- Create a fizzbuzz class library with a method
- that returns Fizz if divisible by 3
- that returns Buzz if divisible by 5
- that returns FizzBuzz if divisible by 3 & 5
- else that returns string of the number
- Create unit test using XUnit
##Module07Lesson05ClassLibraryUnitTestExcerciseApp
- Create a math operation class library
- that adds, subtracts, multiplies, divides two numbers
- Create unit test using XUnit