owned this note
owned this note
Published
Linked with GitHub
# C# youtube tutorial series
###### tags: `youtube series`
- reference: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/
- c# guide: https://docs.microsoft.com/en-us/dotnet/csharp/getting-started/introduction-to-the-csharp-language-and-the-net-framework
# Tutorial outline
- language fundamentals
- advanced language features
- first console app
- making http requests, server/client basics
- first web app (api + UI)
### Rundown of C#/.NET
- cross platform, open source developer platform
- types of applications: ASP.NET - web, Xamarin - Mobile, Unity - games
- what is .NET core/framework
- .NET Core: cross platform implementation of .NET framework
- .NET Framework: used for windows based apps/websites
- Xamarin/Mono: Subset of .NET with extra functionality for mobile/games
- CLR (C#, F#, VB)
- C#: modern, object-oriented, and type-safe
- F#: cross platfor, open-source, functional (includes object-oriented, imperative)
- Visual Basic: simple, type-safe, object-oriented
- NuGet: package manager
- Visual Studio: IDE used to build and run applications
## Type system
- what is a type, what type of object are we talking about
- unified type system, everything (int, double, etc) inherits from object
- type safe, unlike JavaScript and Python
- statically types
## Basic Arithmetic
- order of operations
- Math library
## User Input
- console vs UI input
## Conditionals
- if/else if/else
- switch
## Enumerated types
## Loops
- for
- foreach
- while
## Lists
- creation
- modification
- looping through them
- search and sort
## How the system stores variables/classes
- variable byte sizes
- picture of memory storage
## Accessor Methods
- public
- private
- protected
- Properties: similar to getter/setter in java, used to access private variables
## Attributes
- metadata about types at run time
## Garbage Collection
- scope
## Exception Handling
- try
- try/catch
- type safe means we cant access null values, index outside arrays, or unsafely typecast
## Interfaces
## Language-Integrated Query (LINQ)
custom data type query: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/linq-and-generic-types
## Delegates and Events
- delegate: pass methods as arguments
- events: details summary: https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/awbftdfh%28v%3dvs.100%29
## Documentation
## Small projects and what to add
# Stream 4
## Threaded Programming
C# supports parallel code execution through "Threads". A Thread is an independent execution path, it can run at the same time as others
When a C# program is started, the Common Language Runtime (CLR) starts the "Main" Thread by requesting it from the operating system.
If your CPU has 4 cores, the CLR creates a "pool" of threads with 4 worker threads, and 4 IO threads by default
The Thread Pool has 2 functions: maintain a queue of work to be done, and hold a collection of threads to do the work
### Thread Pool talk
The .NET thread pool injects/removes threads every 0.5 seconds.
If adding a thread doesn't increase throughput, it removes a thread (CLR Hill-Climbing technique)
Assume you are running an ASP.NET app on IIS, and your server has 1 CPU.
There are 100 requests coming in.
The first 4 are handled by the default 4 threads, and then the other 96 wait in a queue until the others are processed
after 0.5 seconds another thread is added to handle the requests. To catch up, it would take awhile
THIS is why Async is awesome. Threads aren't blocked while requests are being handled, so those 4 threads would free up ASAP
### Background threads
Background threads do not keep the application running on the CLR when it is shutdown
## Async
In asynchronous programming a method is called that runs in the background and the calling thread is not blocked.
After calling the method the execution flow immediately backs to calling thread and performs other tasks.
Normally it uses Thread or Task
Three Async patters:
(1) Asynchronous Programming Model (APM) pattern
(2) Event-based Asynchronous Pattern (EAP)
(3) Task-based Asynchronous Pattern (TAP). This is recommended to use by Microsoft.
(1) and (2) were replaced by the async/await pattern (3) in C# 4.5
Tasks use a thread from the ThreadPool
Tasks can be run: In the current thread, in a new thread, in a thread from the Thread Pool, or even without a thread
We don't need to worry about creation or use of threads, the .NET framework handles the inner difficulites
We need to make our own thread if we can control over it like: setting a name, priority, or foreground/background
## HTTP
- request and response
## APIs and HTTP
similar to interfaces, but interfaces between a program and some dataset (a web service, operating system, another application)
- postman requests
http://www.albahari.com/threading/
https://www.infoworld.com/article/3201030/understand-the-net-clr-thread-pool.html
https://stackoverflow.com/questions/11276314/asynchronous-programming-apm-vs-eap
https://www.codeproject.com/Articles/996857/Asynchronous-programming-and-Threading-in-Csharp-N
https://jsonplaceholder.typicode.com/
## Testing