C# crash course Flashcards
What is C#?
OOP, high level programming language developed by Microsoft as part of its .Net ecosystem
What are some advantages of C# compared to other languages?
- Cross platform with .Net core
- Strong memory management (garbage collection)
- Seamless integration with Microsoft
- LINQ, enables SQL-lite quieries directly in C#
- Supports asynchronous
What are records?
A group of variables (unchangeable once created)
What is a struct?
Used for storing data types, (class with no methods). Exists in memory, therefore fast to access
What is an interface?
An interface defines properties and methods implementing classes must implement
What is a task in C#?
Represents an asynchronous operation that allows you to run code concurrently without blocking the main thread
What is async and await used for?
Allows you to write asynchronous code. Await is used to suspend the execution of the async method until the asynchronous tasks completes.
What does ‘Parallel.ForEach’ do?
Runs loop iterations in parallel, making it efficient for CPU-bound tasks.
What is a lock in C#
Prevents multiple threads from accessing a code block simultaneously, only one thread can execute this block at a time
What is a mutex?
A cross-process lock that can be used for synchronization across different applications
What is a semaphore?
Limits the number of threads that can access a resource concurrently
What is inheritance vs composition?
Inheritance one class inherits from another, composition one class contains another
What is an abstract class?
A class that can provide default implementations but cannot be instantiated.
What’s the difference between a task and a thread?
Task is managed by .NET and is better for scalability. Thread is a lower-level construct that gives direct control but is resource heavy
How does dependency injection work in .NET?
Allows you to inject dependencies at runtime using constructors or properties, promoting loose coupling.
What is an example of polymorphism?
Creating an animal class with the method makeNoise and a child class like dog overriding it
What are implicit typed variables ?
Variables types that are determined by the compiler