C# & .NET: Language and Runtime Fundamentals
C# & .NET: Language and Runtime Fundamentals
Up to 20 questions, shuffled on every run
Ready to test how well you know C# and the .NET runtime? This quiz walks through the type system, LINQ, async/await, the CLR and garbage collection, and modern features like records and pattern matching. Take your time and read the explanations. That is where the learning happens.
Answer key and explanations20 questions
The quiz above draws 20 questions at random from these 26, so a second attempt will not be the same run. Everything in the pool is listed here.
What is the key difference between a value type and a reference type in C#?
AnswerValue types are stored by their value; reference types are stored as a reference to data elsewhere.
A value type variable holds the data directly, while a reference type variable holds a reference (pointer) to the data. Assigning a value type copies the value; assigning a reference type copies the reference.
What is a struct in C#?
AnswerA value type, typically used for small, immutable data.
struct declares a value type. Structs are copied on assignment and do not support inheritance from other structs or classes (though they can implement interfaces).
What does boxing refer to in .NET?
AnswerWrapping a value type in an object so it can be treated as a reference type.
Boxing converts a value type to object (or an interface), allocating it on the heap. Unboxing extracts it back. Excessive boxing hurts performance.
What are nullable reference types (introduced in C# 8)?
AnswerA compiler feature that flags where a reference might be null, using ? to mark nullable references.
Nullable reference types are a compile-time feature. With the feature enabled, string is non-nullable and string? is nullable, and the compiler warns about potential null dereferences.
Which access modifier makes a member visible only within its own class?
Answerprivate
private restricts access to the declaring type. internal is assembly-wide, protected is the type plus derived types, and public is unrestricted.
What is the difference between an interface and an abstract class in C#?
AnswerA class can implement many interfaces but inherit only one (abstract) class.
C# has single inheritance for classes but allows a type to implement multiple interfaces. Abstract classes can carry state and implementation; interfaces primarily define a contract (with default members since C# 8).
What is a C# property?
AnswerA member that exposes get and/or set accessors, looking like a field but backed by methods.
Properties provide controlled access to data through get and set accessors, so you can add logic or validation while keeping field-like syntax.
What problem do generics solve?
AnswerThey let you write type-safe, reusable code that works across many types without boxing or casting.
Generics like List<T> provide compile-time type safety and avoid the boxing and casting that came with the old object-based collections.
What is a delegate in C#?
AnswerA type that represents a reference to a method with a specific signature.
A delegate is a type-safe function pointer. Func<>, Action<>, and events are all built on delegates.
How do events relate to delegates?
AnswerAn event is a delegate wrapped so that only the declaring type can invoke it, while others can only subscribe or unsubscribe.
The event keyword restricts a delegate so external code can use += and -= but cannot invoke or overwrite the delegate directly, which enforces the publish/subscribe pattern.
What does a lambda expression such as x => x * 2 create?
AnswerAn anonymous function that can be assigned to a delegate or expression type.
A lambda is a concise anonymous function. It can become a delegate (Func/Action) or, in LINQ-to-SQL style scenarios, an expression tree.
What is the difference between LINQ query syntax and method syntax?
AnswerThey are two ways to write the same queries; the compiler translates query syntax into method calls.
from x in xs where ... select ... (query syntax) compiles to the same Where/Select method calls. It is a style choice, not a behavioral difference.
What is deferred execution in LINQ?
AnswerA query is not run until you enumerate its results, for example with foreach or ToList().
Most LINQ operators build up a query that executes lazily when enumerated. Calling ToList(), ToArray(), Count(), etc. forces immediate execution.
Which LINQ operator returns the number of elements?
AnswerCount()
Count() forces execution and returns the element count. Select projects, Where filters, and OrderBy sorts.
What does the await keyword do?
AnswerIt asynchronously waits for a Task to complete without blocking the calling thread.
await suspends the async method and returns control to the caller until the awaited Task completes, then resumes, all without blocking the thread.
What is the difference between Task and Task<T>?
AnswerTask represents an async operation with no result; Task<T> represents one that produces a value of type T.
Awaiting a Task yields no value (like a void async method), while awaiting a Task<T> yields a T.
What is a CancellationToken used for?
AnswerTo signal that an asynchronous operation should be cancelled cooperatively.
A CancellationToken is passed into async methods, which check it and stop cooperatively. It does not forcibly abort anything; the operation must observe the token.
What does the CLR do?
AnswerIt is the runtime that executes .NET code, providing JIT compilation, garbage collection, and type safety.
The Common Language Runtime executes managed code, compiling IL to native code with the JIT, managing memory via the garbage collector, and enforcing type safety.
What is IL (Intermediate Language)?
AnswerThe CPU-independent bytecode that C# compiles to, which the CLR then JIT-compiles to native code.
C# compiles to IL (also called CIL/MSIL) stored in assemblies. At run time the JIT compiler turns IL into native code for the current machine.
How does .NET garbage collection reclaim memory?
AnswerIt automatically frees objects that are no longer reachable, using a generational collector.
The GC tracks object reachability and reclaims unreachable objects. It is generational (Gen 0, 1, 2) because most objects die young, which makes collection efficient.
What is an assembly in .NET?
AnswerA compiled unit of code and resources, typically a .dll or .exe, that the CLR loads.
An assembly is the deployment and versioning unit of .NET, containing IL, metadata, and resources, usually as a DLL or EXE.
What does the using statement (as in using var f = ...) guarantee?
AnswerThat Dispose() is called on the object when the block or scope ends, even if an exception is thrown.
using ensures deterministic cleanup by calling Dispose() (from IDisposable) when the scope exits, which is how you release files, connections, and other unmanaged resources.
What is a record type in modern C#?
AnswerA reference (or value) type with built-in value-based equality and concise syntax, good for immutable data.
record types generate value-based equality, a concise constructor, and with-expressions for non-destructive mutation, making them ideal for immutable data models.
What does pattern matching with switch expressions provide?
AnswerA concise way to branch on the shape or value of data and return a result.
Switch expressions and patterns (type, property, relational, and more) let you match on data shape and produce a value, which is more expressive and safer than long if/else chains.
What is NuGet?
AnswerThe package manager for .NET, used to add and manage library dependencies.
NuGet distributes reusable .NET libraries as packages, referenced through the .csproj file and restored by the SDK.
What is the role of the .csproj file?
AnswerIt defines the project: target framework, dependencies, and build settings.
The .csproj is an MSBuild project file describing the target framework, package references, and other build configuration used by the dotnet CLI and SDK.





