Module 1 · Foundations · Lesson 1 of 22
Common misconceptions, corrected
Do value types always live on the stack? Does async create a new thread? This lesson corrects seven C# interview misconceptions with code you can run.
Interviewers like these seven statements because many developers repeat them from memory, and each one is only partly true. A candidate who says "value types live on the stack" often cannot answer the next question: "What about a struct that is a field of a class?"
For each misconception you get four things: the idea in plain words, a small program to run, the mistake to avoid, and a sentence you can say in an interview. You only need to be able to read simple C#: a variable, a method call and a small class.
The seven misconceptions, and what is true instead
| What people say | What is true |
|---|---|
| "Value types live on the stack." | Where a value is stored depends on where the variable is. A struct that is a field of an object is stored inside that object. |
"async starts a new thread." | await does not start a thread. It only pauses the method when the work it waits for is not finished yet. |
"IQueryable<T> is just a faster IEnumerable<T>." | IQueryable<T> holds a description of the query. A provider can translate that description. With EF Core, a .NET library for databases, a provider for a relational database can translate a supported query into SQL, the query language of such databases. |
"new List<T>(10) holds 10 items." | It holds 0 items. The 10 is reserved room, called capacity. |
| "A hash code identifies a value." | Two different values can have the same hash code. |
"foreach makes a collection read-only." | Nothing is locked. A List<T> lets you change it, and then the loop throws on its next step. |
| "The garbage collector disposes my resources." | The garbage collector frees memory. It does not call Dispose. |
The rest of the lesson takes these one at a time.
How to use this lesson
Each example below is a complete program. Before you run one, write down what you think it prints. Then run it and compare. If you were wrong, find the line that surprised you. That line is what you learn from.
You can run an example on this page with Try it. To run it on your own computer, create a console project with dotnet new console, replace the content of Program.cs with the example, and type dotnet run. Use one project for each example. The examples were run on .NET 10, in a project as that command creates it. Such a project has implicit usings switched on, which is why the examples need no using System; line at the top.
Warm up: room for ten items is not ten items
A List<string> is a list of strings that can grow. When you create one, you may pass a number: new List<string>(10). What does the 10 mean? Guess the two lines this program prints.
var names = new List<string>(10);
Console.WriteLine(names.Count);
names.Add("Asha");
Console.WriteLine(names.Count);It prints 0 and then 1.
new List<string>(10)creates an empty list. The 10 only reserves room for ten strings, so that the list does not have to make room again each time you add one. That reserved room is called the capacity.Countis the number of items that are really in the list. Nothing has been added yet, so the first line prints0.names.Add("Asha")adds one name, so the second line prints1.
Think of an egg tray with ten places. An empty tray has room for ten eggs, but it holds no eggs.
After new List<string>(10), what are Count and the initial Capacity before any Add call?
Show answer
Correct answer: B
The constructor reserves storage for ten elements but leaves the list empty. Count changes when you add or remove elements.
Hint: Separate the room reserved from the items actually present.
The whole lesson works this way: a rule, a small program that shows it, and a clear idea of what the program does not show.
1. Do value types always live on the stack?
No. First, the words you need.
- A value type variable holds the data itself. For example,
int,bool,doubleand everystructare value types. - A reference type variable holds a reference to an object, or
nullwhen it refers to no object. Everyclassis a reference type. The object is created somewhere in memory, and the variable only says where to find it, a bit like a house address. - The call stack is the memory a thread uses to keep track of the methods that are running right now. A method's local variables can be kept there while the method runs.
- The heap is the large area of memory where objects are normally created.
The myth says: "It is a value type, so it is on the stack." But where a value is stored depends on where the variable is, not only on its type.
Look at the program below. MutablePoint is a struct, so it is a value type. Holder is a class, and it has one field of type MutablePoint. A field is a variable that belongs to a class or a struct. This one is an instance field: every Holder object has its own Point. (A field marked static is different. It belongs to the class itself, not to each object.)
// 1. A struct instance field is part of its containing object, not a separate box.
var holder = new Holder();
holder.Point.X = 5; // writes the inline struct field; this does not measure allocation
Console.WriteLine($"1. struct field inside a class: {holder.Point.X}");
struct MutablePoint { public int X; }
sealed class Holder { public MutablePoint Point; }1. struct field inside a class: 5
new Holder() creates one object. The struct Point is not a separate thing somewhere else. Its data sits inside that object, the way a drawer sits inside a desk.
flowchart TD
v["holder<br/>(a variable)"]
subgraph o["one Holder object"]
p["Point<br/>(a MutablePoint)<br/>X = 5"]
end
v -- "refers to" --> o
So if the Holder object is on the heap, the data of the struct is on the heap too, although MutablePoint is a value type.
The line holder.Point.X = 5 means: go to the object that holder refers to, find the Point inside it, and set its X to 5.
What the program does not show. It prints 5, so we know the value of the field. Printing a value does not tell us where it was stored. .NET is free to choose the place, as long as your program behaves the same. A local int, for example, may be kept on the stack or in a CPU register, which is a tiny, very fast storage place inside the processor (the CPU).
The mistake to avoid. Do not describe a type by the place where it is stored. Describe it by what happens when you copy it. Copying a value type copies the data. Copying a reference type copies the reference, so both variables refer to the same object. The next lesson starts with a small program that shows both kinds of copying.
In an interview, say: "A value type is copied by value. Where its data is stored depends on where the variable is. A struct that is an instance field of a class is stored inside the object, so it lives wherever that object lives. Value type does not mean stack."
Going deeper. There are more cases than this one. A value that is an element of an array is stored inside the array. When an int is converted to object, .NET copies it into a new object; this is called boxing. And .NET can change where things are stored when that is safe: newer versions can even keep some objects off the heap. In the next lesson, Question 4 compares value types and reference types, and Question 30 covers the stack and the heap.
2. Does async create a new thread?
No. First, the words you need.
- A thread is one line of work inside your program. It runs your code one statement after another. A program can have several threads.
- A task (the type
Task) is an object that stands for work that will be finished at some point: reading a file, calling a web service, waiting 100 milliseconds. The work may already be finished, or it may finish later. awaitmeans: "I need this task to be finished before I go on."
What await does depends on one question: is the task already finished?
flowchart TD
a["Your method reaches an await"] --> q{"Is the task already finished?"}
q -- "Yes" --> y["No pause: await gives the result at once, or throws the task's error"]
q -- "No" --> n["The method pauses and gives control back to its caller"]
n --> l["When the task finishes, the rest of the method runs"]
- If the task is already finished, the method does not pause.
awaitgives the result at once, and the method carries on with the next line on the same thread. If the task failed or was canceled,awaitthrows the exception at this line instead. - If the task is not finished, the method pauses at that line and gives control back to the code that called it. The thread is free to do other work. Later, when the task finishes, the rest of the method runs.
In both cases await itself does not create a thread, and it does not keep a thread waiting.
The program below awaits a task that is already finished. Task.CompletedTask is a ready-made finished task. Environment.CurrentManagedThreadId is the number of the thread that is running the code right now.
// 2. This completed-task example demonstrates the synchronous await path only.
int before = Environment.CurrentManagedThreadId;
await Task.CompletedTask;
Console.WriteLine($"2. same thread after awaiting a completed task: {before == Environment.CurrentManagedThreadId}");2. same thread after awaiting a completed task: True
Step by step:
beforeremembers the number of the current thread.await Task.CompletedTaskfinds that the task is already finished, so the method does not pause.- The last line reads the thread number again. It is the same thread, so the program prints
True.
What the program does not show. It shows only the "already finished" path. It does not show a real pause, and it says nothing about which thread runs the rest of a method after a pause.
So who does the work? That depends on the operation, not on await. While a program waits for data from a network, usually no thread is busy with that wait: the operating system tells .NET when the data has arrived. Reading and writing files depends on the method you call and on the operating system. Heavy calculation is different again. If you start it with Task.Run, it runs on a thread from the thread pool, a set of threads that .NET keeps ready for such work.
The mistake to avoid. Do not say "async means multithreading". The word async on a method lets you use await inside it. It does not move the method to another thread. Work moves to another thread when you ask for that, for example with Task.Run.
In an interview, say: "await does not start a thread and does not block the calling thread. If the task is already complete, the method continues at once, with the task's result or its exception. If it is not, the method is suspended and its caller gets control back; when the task completes, the rest of the method continues. Whether a thread works in the meantime depends on the operation: waiting for a network answer usually needs none, and heavy calculation started with Task.Run uses a thread-pool thread."
Going deeper. After a real pause, the rest of the method may run on a different thread from the one that started it. In a console program it usually continues on a thread-pool thread. A desktop application normally brings it back to the thread that owns the screen. So never promise a particular thread in an interview unless you know the kind of application. The lesson Async, threading, and concurrency covers this in detail.
3. Is IQueryable just a faster IEnumerable?
No. They look alike, but they work in different ways. First, the words you need.
- LINQ is the set of methods such as
Where,SelectandOrderBythat you use to ask questions of data. - A lambda is a small function written with
=>. For example,n => n % 2 == 0means: "take a numbernand tell me whether it is even." The%gives the remainder of a division, son % 2 == 0is true for even numbers. IEnumerable<T>is the interface of a sequence that you can go through withforeach, such as an array or a list. (An interface is a list of members that a type promises to have.) TheTstands for the type of the items. For such a sequence, LINQ'sWherereceives your lambda as compiled code. That code runs in your program, for one item after another.IQueryable<T>looks the same in your code, but itsWherereceives your lambda as data: a description of the code, called an expression tree. A provider can read that description and translate it. EF Core is a .NET library for working with databases. Its provider for a relational database can translate a supported query into SQL, the language that such databases understand, and then the database does the filtering.
flowchart TD l["Your lambda<br/>n => n % 2 == 0"] l -- "IEnumerable" --> f["Compiled code"] f --> m["Runs in your program, in memory"] l -- "IQueryable" --> e["Expression tree: the query as data"] e --> p["A provider reads it and translates it"] p --> s["For example, EF Core produces SQL for the database"]
So IQueryable<T> is not a faster IEnumerable<T>. It lets the work happen in another place, when a provider can translate the query. With a database this usually means that fewer rows travel to your program.
The program below shows that a query can be kept as data. Guess what its three lines look like.
using System.Linq.Expressions;
// 3. IQueryable holds an expression tree that a provider interprets.
IQueryable<int> q = new[] { 1, 2, 3, 4 }.AsQueryable().Where(n => n % 2 == 0);
Console.WriteLine($"3. expression: {q.Expression}");
Expression<Func<int, bool>> isEven = n => n % 2 == 0;
Console.WriteLine($" lambda as data: {isEven.Body}");
Console.WriteLine($" results when the query runs: {string.Join(", ", q)}");3. expression: System.Int32[].Where(n => ((n % 2) == 0)) lambda as data: ((n % 2) == 0) results when the query runs: 2, 4
Step by step:
new[] { 1, 2, 3, 4 }.AsQueryable()wraps a normal array so that it can be used as anIQueryable<int>..Where(n => n % 2 == 0)does not test any number yet. It only adds "where n is even" to the description of the query.q.Expressionis that description. Printing it shows the query as text. No number was tested to print this line.- The next two lines store the same lambda in an
Expression<Func<int, bool>>.Func<int, bool>is the type of a function that takes anintand returns abool. Wrapped inExpression<...>, the lambda is data, and the program can print its body. - Only the last line runs the query:
string.Joingoes throughq, and now the numbers are tested. The results are 2 and 4.
What the program does not show. No database takes part here. The array is in memory, so the numbers in the last line were filtered in your program. The example shows that a query can be stored as data. It does not show a translation to SQL. To see that, you need a real EF Core query and the SQL it produces. The exact text printed for an expression is also a detail of .NET, not a promise.
The mistake to avoid. With EF Core, it matters where you stop using IQueryable<T>. If you call ToList() first and filter afterwards, every row that the query has selected so far is loaded into memory, and your program does the filtering. Also, a provider cannot translate every C# expression. It can throw an exception for one that it does not understand.
In an interview, say: "With IEnumerable<T>, LINQ runs my lambdas as compiled code inside my program. IQueryable<T> keeps the query as an expression tree, and a provider such as EF Core translates what it supports, for example to SQL. Where the query runs depends on the provider and on the point where I load the results, for example with ToList."
Going deeper. A query runs when you ask for its results. ToList and ToArray load all results into memory; this is called materializing them. First and Count return a single answer. A foreach loop reads the results one after another. The lessons Collections, LINQ, and data structures and EF Core and data access come back to this.
4. Does new List<T>(10) hold ten items?
No. You saw this in the warm-up: it holds none. This program prints both numbers side by side.
// 4. Capacity is not Count.
var list = new List<string>(10);
Console.WriteLine($"4. Count={list.Count} Capacity={list.Capacity}");4. Count=0 Capacity=10
Why does capacity exist at all? A List<T> keeps its items in an array inside it. An array cannot grow. When that array is full and you add one more item, the list must create a bigger array and copy every item into it. If you already know that you will add about ten thousand items, new List<string>(10_000) reserves the room once, and the list does not have to copy its items again and again while it grows.
The mistake to avoid. After var list = new List<string>(10);, the line list[0] = "Asha"; throws ArgumentOutOfRangeException, because there is no item 0 yet. Use Add. An array is different: new string[10] really has ten places, and each one holds null until you fill it.
In an interview, say: "Capacity is the size of the list's internal array, so it is the number of items the list can hold before it has to grow. Count is the number of items that are in the list now. new List<T>(10) gives Count 0 and Capacity 10."
5. Is a hash code unique?
No. Two different values can have the same hash code.
First, what a hash code is. GetHashCode() turns a value into an int. Collections such as Dictionary<TKey, TValue> and HashSet<T> use that number to find things quickly.
Picture a filing cabinet with one drawer for each first letter. To find "Sharma" you open drawer S and look only there. The letter narrows the search, but many names share a drawer. A hash code is like the drawer. It is not the name.
Why can a hash code not be unique? Count the possibilities. A long can hold about 18 billion billion different values. A hash code is an int, which has only about 4 billion. There are far more long values than hash codes, so some different values must share one. When two different values have the same hash code, we call it a collision.
// 5. In the .NET 10 implementation, Int64.GetHashCode XORs its two 32-bit halves.
long a = 1, b = 1L << 32;
Console.WriteLine($"5. {a}.GetHashCode()={a.GetHashCode()}, {b}.GetHashCode()={b.GetHashCode()}, equal values: {a == b}");5. 1.GetHashCode()=1, 4294967296.GetHashCode()=1, equal values: False
Step by step:
ais 1.bis1L << 32. TheLmakes the 1 along, and<< 32moves it 32 binary places to the left. The result is 4,294,967,296.- The two numbers are different, so
a == bisFalse. - Both hash codes are
1. Alonghas 64 bits, and .NET 10 builds its hash code by combining the upper 32 bits with the lower 32 bits. (The operation it uses is called XOR, as the comment in the code says. XOR compares two numbers bit by bit and gives a 1 wherever the bits differ.) For the number 1 these halves are 0 and 1. For 4,294,967,296 they are 1 and 0. Combining them gives 1 both times.
So how does a dictionary still work? It uses the hash code only to pick the drawer. (The usual word for such a drawer is bucket.) Then it compares the keys in that drawer with Equals. Two keys with the same hash code and different values are both kept, and both can be found.
The rule goes in one direction only:
- Values that are equal must have the same hash code.
- Values with the same hash code are not always equal.
The mistake to avoid. Do not use a hash code as an ID, and do not save it in a file or a database. The numbers can change between .NET versions. For a string they can even be different each time the program starts.
In an interview, say: "No. A hash code is an int, so different values can share one. That is a collision. The rule is that equal values must return the same hash code. The reverse is not guaranteed: equal hash codes do not prove that two values are equal. A dictionary uses the hash code to find the bucket and Equals to confirm the match."
Going deeper. The lesson after the next one has two questions on this: Question 40 explains why Equals and GetHashCode must be overridden together, and Question 41 shows a set that keeps two names with the same hash code.
6. Can you change a list inside foreach?
Many people say that foreach makes a collection read-only. It does not. First, what foreach does.
foreach asks the collection for an enumerator. That is a small helper object that walks through the items one at a time. Before each item, the loop asks the enumerator: "Is there a next one?" The method it calls for this is named MoveNext.
Nothing locks the collection while the loop runs. You can call Add inside the loop, and the call works. What happens after that is decided by the collection. Guess what this program prints.
// 6. Adding succeeds, but invalidates the List<T> enumerator; its next MoveNext throws.
var numbers = new List<int> { 1, 2, 3 };
try
{
foreach (var n in numbers)
if (n == 2) numbers.Add(4);
}
catch (InvalidOperationException ex)
{
Console.WriteLine($"6. {ex.GetType().Name}");
}
Console.WriteLine($" items in the list after the loop: {numbers.Count}");6. InvalidOperationException items in the list after the loop: 4
Step by step:
- The loop reads 1. Nothing happens.
- The loop reads 2.
numbers.Add(4)runs and succeeds. The list now holds 1, 2, 3 and 4. - The loop asks for the next item. A
List<T>counts its changes, and its enumerator sees that the list has changed since the loop started. It refuses to go on and throwsInvalidOperationException. - The
catchblock prints the name of the exception. - The last line shows that the exception did not undo the
Add: the list has 4 items.
In .NET 10 the message of this exception is "Collection was modified; enumeration operation may not execute."
Why does the list do that? If items are added or removed while you walk through them, you could skip an item or see one twice. Stopping with an error is safer than giving a wrong result.
The same exception comes when you remove an item inside the loop, or replace one with numbers[0] = 9. Changing something inside an item is different. If the list holds objects, person.Name = "Asha" inside the loop is fine, because the list itself did not change.
The mistake to avoid. Removing items from a list inside a foreach over the same list. Do one of these instead:
- Loop over a copy:
foreach (var n in numbers.ToList()). - Let the list remove them:
numbers.RemoveAll(n => n == 2). - Collect the changes during the loop and apply them after it.
In an interview, say: "foreach does not make a collection read-only. For List<T>, adding, removing or replacing an element while the loop runs invalidates the enumerator, and its next MoveNext throws InvalidOperationException. Other collections have their own rules."
Going deeper. One thing really is read-only in an ordinary foreach like the one above: the loop variable. Inside that loop, n = 5; does not compile. Other collections decide for themselves what they allow during a loop, so read the documentation of the collection you use. The text of an exception message can also change between .NET versions and languages, so do not write code that depends on it.
7. Does the garbage collector call Dispose?
No. The two do different jobs.
- The garbage collector (GC) frees the memory of objects that your program can no longer reach. Normally .NET decides when it runs.
- Some objects hold something that is not memory: an open file, a network connection, a database connection. The operating system or the database keeps it open until someone says "I am done." Such an object has a method named
Disposefor exactly that. Its class implements the interfaceIDisposable, which consists of that one method.
The GC knows about memory. It does not know that your file should be closed now, and it does not call Dispose. You call it. The easy way is the using statement.
// 7. using calls Dispose on scope exit; this logging stand-in owns no real handle.
using (var r = new Resource("example resource"))
Console.WriteLine("7. using block body runs");
Console.WriteLine(" after the using block");
sealed class Resource(string name) : IDisposable
{
public void Dispose() => Console.WriteLine($" Dispose({name}) called at the end of the using block");
}7. using block body runs Dispose(example resource) called at the end of the using block after the using block
Step by step:
new Resource("example resource")creates the object. The(string name)after the class name is a short way to give the class a constructor with one parameter.- The body of the
usingstatement runs and prints the first line. - When the body ends,
usingcallsr.Dispose(), which prints the second line. This happens before the next statement. - The program goes on and prints the third line.
using calls Dispose even when the body ends because of an exception or a return. It works like try and finally.
What the program does not show. Resource only prints a line. It does not hold a real file. The example shows when Dispose is called, not what a real resource does.
The mistake to avoid. Thinking "the GC will clean it up". If you forget to dispose a file stream, the file can stay locked. If you forget to dispose database connections, the application can run out of connections.
In an interview, say: "The GC reclaims managed memory, the memory that .NET looks after. It does not call Dispose. I release the resources my code owns, such as the files and connections it opened, promptly with using, or with await using when the disposal is asynchronous. A finalizer is only a safety net that may run later. It does not replace Dispose."
Going deeper. A finalizer is a method that the GC may run some time before it frees an object. Types such as SafeHandle use one as a fallback, in case nobody called Dispose. You cannot know when it runs, so it is no replacement. Also, using cannot help when the whole process is stopped suddenly. The lesson Resource handling, files, and data access goes further.
What an example proves, and what it does not
Most parts above have a paragraph called "What the program does not show". That habit matters in an interview. A good candidate says what was observed and stops there. A weak candidate turns one small result into a big claim.
Try it yourself. A candidate runs the examples of this lesson and says: "The output is correct, so this proves that EF Core translated my query to SQL, and that await moved the work to another thread." What is wrong with each claim, and what would you check instead? Think about it first, then compare.
| What the example showed | What you can say | What needs another check |
|---|---|---|
| A query over an array printed its expression tree | The query is stored as data | To see SQL, run a real EF Core query and look at the SQL it produces |
await on a finished task stayed on the same thread | A finished task does not pause the method | To see a real pause, await something that is not finished yet. Do not promise a particular thread afterwards |
| A struct field printed 5 | The field has the value 5 | Printing a value does not tell you where the memory is |
Which of these statements do the examples of this lesson really support?
Show answer
Correct answer: B
The example in part 2 awaited Task.CompletedTask, a task that was already finished, so the method did not pause. The other three statements need a check that the examples never made.
Option A: await does not create threads. No example showed a new thread.
Option C: The array is in memory. No database and no EF Core provider took part.
Option D: Printing a value shows the value, not the place where it is stored.
Hint: For each statement, ask which line of which program would have shown it.
How to answer an interview question
Use the same four steps for every question in this course.
- State the rule. Say what the feature guarantees, in one or two sentences. Example: "
Nullable<T>is a struct that holds either a value of its underlying non-nullable value type or no value, andHasValuetells you which." - Give one example. One line of code or one small situation. Short is better than complete.
- Say what it costs or when it breaks. An exception, extra memory, a deadlock, a wrong result.
- Say how you would check. For a claim about speed, name what you would measure: a benchmark, a profiler or a query plan. For code that runs on several threads or several servers, say what must always stay true, and what happens after a cancellation, a retry or a failure half-way.
Here is the difference. A weak answer to "Is string a value type?" is: "No, it is a reference type."
A strong answer is: "No, string is a reference type. But it is immutable, which means its text cannot change after it is created, and == compares the text. So it often behaves like a value. If I build a long string in a loop with +=, I can create many strings and copy the same text again and again, so for many appends I consider StringBuilder, and I measure when speed matters."
How to study with this course
- Answer aloud first. Read the question, cover the answer and say your own answer for about a minute. Then compare.
- Keep a list of your mistakes. Write down the question number, what you wrongly assumed, and one small example that shows why it is wrong. Try that question again the next day, before you read the answer again. Trying again at once is practice, but it does not show that you will remember.
- Change one thing. After you read an answer, change one condition and check whether your answer still holds: a struct instead of a class, two threads instead of one, a retry after a timeout.
- Run the code. The examples in this lesson are complete programs for .NET 10. In later lessons some examples are only part of a program, some are wrong on purpose, and some need ASP.NET Core or EF Core. Each lesson says what its examples need. When you note a result, also note the .NET version and the project settings you used. A small console program also cannot prove that a database query, a deployment or a speed claim works in production.
- Do not read all 222 questions in one sitting. Go through the course in four rounds: first the language, types and objects; then collections, data and resources; then async and memory; then web APIs, the platform and architecture.
- Use the tests. Each lesson has a short online practice test with its own questions. The module "Module Practice Tests and Final Mock" has six practice tests of eight questions and a mock interview of 25 questions to do in 35 minutes with your own timer. You mark those yourself. Take the matching practice test after each module and the mock at the end. Write a reason for each answer, and come back to your mistakes with a changed example. No score can promise how an interview will go.
This course is a set of questions with answers. It does not replace learning the language step by step. If you need something else first, use this table.
| If you... | This course helps you... | Also use... |
|---|---|---|
| are new to C# | find out what you do not know yet | the step-by-step courses C# Beginner, C# Intermediate and C# Advanced |
| can write code but find it hard to explain | say the rules exactly and handle follow-up questions | C# Practice: Console Apps, Files and HTTP, where you build one small application step by step |
| need practice with whole applications | revise the rules about APIs, data and failures | C# and .NET 10: Application Engineering Labs |
| are preparing for senior or behavioral rounds | check your technical statements | Senior .NET and C# Interview Preparation and the Behavioral and Senior-Round Playbook |
Course map
| Module | Questions | Focus |
|---|---|---|
| Foundations | 1-30 | Types, strings, numbers, access modifiers, memory basics |
| Object-oriented C#, delegates and generics | 31-49 | Interfaces, delegates and events, variance, equality, reflection |
| Collections, LINQ and data access | 50-84 | Enumeration, LINQ execution, collections, resources, EF Core |
| Async, concurrency and memory | 85-126 | Tasks, locks, channels, cancellation, GC and diagnostics |
| ASP.NET Core and Web APIs | 127-165 | Middleware, DI, auth, configuration, hosting and scaling |
| Modern C#, architecture and practice | 166-222 | Current C# features, clean code, patterns, testing, security |
The questions are numbered continuously, so a reference such as "Question 93" always points to the same answer. Start with Question 1 in the next lesson, Core C# and CLR basics.
Sources
Every fact in this lesson was checked against official documentation, and every program was run on .NET 10.
- Value types and storage: Microsoft Learn, Value types and Structure types; C# language specification, Variables; .NET Blog, Performance improvements in .NET 10
asyncand threads: Microsoft Learn, The task asynchronous programming model (see "Threads"), The await operator and Asynchronous programming scenariosIQueryable<T>: Microsoft Learn, Expression trees, IQueryable<T> and, for EF Core, Querying data and Client vs. server evaluationList<T>capacity: Microsoft Learn, List<T>.Capacity- Hash codes: Microsoft Learn, Object.GetHashCode and String.GetHashCode; .NET runtime source, Int64.GetHashCode in .NET 10
foreachand changing a list: Microsoft Learn, List<T>.GetEnumerator and Iteration statementsDisposeand the garbage collector: Microsoft Learn, Using objects that implement IDisposable, The using statement, Finalizers and Fundamentals of garbage collection
Practice
TechInterviewNotes Editorial Team · Updated 28 Oct 2026 ·