Knowledge Base
Articles
Notes and deep dives on .NET, C#, software engineering and AI.
Repository Pattern for .NET Repository Pattern για .NET
Interfaces, dependency injection and testing, with ASP.NET Core code.
Read articleUnderstanding Dependency Injection in C# .NET Κατανοώντας το Dependency Injection σε C# .NET
A beginner-friendly guide to DI, with a real payment provider example and unit tests.
Read articlePolymorphism in C#: virtual and override vs new Πολυμορφισμός σε C#: virtual και override έναντι new
Why method hiding with new is not polymorphism, with a runnable Animal and Dog example.
Read articleDelegates in C#: a Notify function as a parameter Delegates σε C#: μια συνάρτηση Notify ως παράμετρος
Swap a Notify function from SMS to email without touching the class that calls it.
Read articleValue Types vs Reference Types in C# Value Types έναντι Reference Types σε C#
Struct vs class, stack vs heap and the exact rule for when ref actually matters.
Read articleType Conversion in C#: Ways, Traps and Correct Patterns Μετατροπή Τύπων σε C#: Τρόποι, Παγίδες και Σωστά Πρότυπα
Casts, Parse, TryParse, Convert and as vs is, with an example that throws every exception on purpose.
Read articleThe 4 Pillars of OOP in C# Οι 4 Πυλώνες του OOP σε C#
Encapsulation, abstraction, inheritance and polymorphism, one running example at a time.
Read articleInterface vs Abstract Class in C# Interface έναντι Abstract Class σε C#
Why both matter for abstraction, how they differ and how each one works with DI.
Read articleThreads and Tasks in .NET Threads και Tasks στο .NET
What a thread is, why Microsoft created Task and how to use it for I/O-bound and CPU-bound work.
Read articleThe ThreadPool in .NET Το ThreadPool στο .NET
Why reusing threads matters, what Task.Run and LongRunning do underneath and how await frees threads during I/O.
Read articlePractice
Exercises
Short snippets like the ones you get in interviews. Guess the output first, then read the explanation.
Task Exercises
Task, async and await: execution order, timings, exceptions and common traps.
1. StartNew with a synchronous lambda 1. StartNew με synchronous lambda
A classic: StartNew, a blocking delay and t.Wait(). What prints and how many threads wait? Ένα κλασικό: StartNew, ένα blocking delay και t.Wait(). Τι τυπώνεται και πόσα threads περιμένουν;
Open exercise2. StartNew with an async lambda 2. StartNew με async lambda
Make the lambda async and the output order changes. Why does All done print first? Κάνε το lambda async και αλλάζει η σειρά του output. Γιατί τυπώνεται πρώτο το All done;
Open exercise3. Fixing StartNew with Unwrap 3. Διόρθωση του StartNew με Unwrap
The same async lambda with .Unwrap() at the end. Does the order come back? Το ίδιο async lambda με .Unwrap() στο τέλος. Επιστρέφει η σωστή σειρά;
Open exercise4. Task.Run with an async lambda 4. Task.Run με async lambda
Replace StartNew with Task.Run and keep the async lambda. What changes? Άλλαξε το StartNew σε Task.Run και κράτα το async lambda. Τι αλλάζει;
Open exercise5. Async all the way 5. Async μέχρι τέλους
No StartNew, no Task.Run, no Wait. Same output, so what did we gain? Χωρίς StartNew, χωρίς Task.Run, χωρίς Wait. Ίδιο output, άρα τι κερδίσαμε;
Open exercise6. What type is t? 6. Τι τύπος είναι το t;
Eight lines, eight variables. Which ones are Task, Task<int> or Task<Task>? Οκτώ γραμμές, οκτώ μεταβλητές. Ποιες είναι Task, Task<int> ή Task<Task>;
Open exercise7. Two awaits, two timings 7. Δύο awaits, δύο χρόνοι
Same two calls, same two awaits. Why does one block take twice as long? Ίδιες δύο κλήσεις, ίδια δύο awaits. Γιατί το ένα block παίρνει τον διπλάσιο χρόνο;
Open exercise8. An async method that never really awaits 8. Μια async μέθοδος που δεν κάνει ποτέ πραγματικό await
The concurrent block from the previous exercise, but GetAsync uses Thread.Sleep. How long now? Το ταυτόχρονο block της προηγούμενης άσκησης, αλλά το GetAsync κάνει Thread.Sleep. Πόσο παίρνει τώρα;
Open exercise9. Same exception, two different types 9. Ίδιο exception, δύο διαφορετικοί τύποι
One failed task, caught twice: once with Wait and once with await. What are the two types? Ένα task που απέτυχε, πιασμένο δύο φορές: μία με Wait και μία με await. Ποιοι είναι οι δύο τύποι;
Open exercise10. WhenAll with two failing tasks 10. WhenAll με δύο tasks που αποτυγχάνουν
Two tasks throw, you await WhenAll. How many exceptions do you see? Δύο tasks πετούν exception, κάνεις await το WhenAll. Πόσα exceptions βλέπεις;
Open exercise11. Calling an async method without await 11. Κλήση async μεθόδου χωρίς await
DoWorkAsync() without await, then A and B. In what order do 1, 2, A and B appear? DoWorkAsync() χωρίς await, μετά A και B. Με ποια σειρά εμφανίζονται τα 1, 2, A και B;
Open exercise12. The forgotten await hides exceptions 12. Το ξεχασμένο await κρύβει τα exceptions
FailAsync throws, but nobody awaits it. Do you see the error? Το FailAsync πετάει exception, αλλά κανείς δεν του κάνει await. Βλέπεις το σφάλμα;
Open exercise