---
title: "C# & .NET: Language and Runtime Fundamentals"
description: "Test your knowledge of C# and .NET covering types, LINQ, async/await, the CLR, generics, and modern .NET features."
author: "Mohammad Abu Mattar"
canonical: https://mkabumattar.com/quizzes/post/csharp-dotnet-fundamentals-quiz
---

# C# & .NET: Language and Runtime Fundamentals

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.

## Questions

### 1. What is the key difference between a value type and a reference type in C#?

- Value types are stored by their value; reference types are stored as a reference to data elsewhere.
- Value types can never be stored on the heap.
- Reference types cannot be passed to methods.
- Value types are always immutable.

**Hint:** Think about what the variable actually holds when you assign it.

### 2. What is a struct in C#?

- A value type, typically used for small, immutable data.
- A reference type that lives on the heap.
- A keyword for declaring interfaces.
- A special kind of class that supports inheritance.

**Hint:** It is the classic example of a value type you define yourself.

### 3. What does boxing refer to in .NET?

- Wrapping a value type in an object so it can be treated as a reference type.
- Encrypting an object before serialization.
- Grouping multiple objects into a collection.
- Marking a class as sealed.

**Hint:** It happens when you assign an int to an object variable.

### 4. What are nullable reference types (introduced in C# 8)?

- A compiler feature that flags where a reference might be null, using ? to mark nullable references.
- A runtime change that makes all references nullable by default.
- A way to make value types hold null.
- A garbage-collection optimization.

**Hint:** It is about compiler warnings, not runtime behavior.

### 5. Which access modifier makes a member visible only within its own class?

- private
- internal
- protected
- public

**Hint:** It is the most restrictive of the four.

### 6. What is the difference between an interface and an abstract class in C#?

- A class can implement many interfaces but inherit only one (abstract) class.
- Interfaces can hold state but abstract classes cannot.
- Abstract classes cannot contain method signatures.
- Interfaces support constructors while abstract classes do not.

**Hint:** Think about how many base types a class can have.

### 7. What is a C# property?

- A member that exposes get and/or set accessors, looking like a field but backed by methods.
- A read-only constant defined at compile time.
- A method that must return void.
- A field that cannot be accessed outside the class.

**Hint:** It uses get and set.

### 8. What problem do generics solve?

- They let you write type-safe, reusable code that works across many types without boxing or casting.
- They automatically parallelize loops.
- They replace the need for interfaces.
- They make all types nullable.

**Hint:** Think about List<T> versus the old ArrayList.

### 9. What is a delegate in C#?

- A type that represents a reference to a method with a specific signature.
- A class that cannot be instantiated.
- A keyword for asynchronous methods.
- A collection of key-value pairs.

**Hint:** It lets you pass a method around like data.

### 10. How do events relate to delegates?

- An event is a delegate wrapped so that only the declaring type can invoke it, while others can only subscribe or unsubscribe.
- Events and delegates are completely unrelated.
- An event replaces the need for a delegate type.
- Events can only be raised from outside the class.

**Hint:** It controls who is allowed to raise it.

### 11. What does a lambda expression such as x => x * 2 create?

- An anonymous function that can be assigned to a delegate or expression type.
- A new thread.
- A compile-time constant.
- A generic type parameter.

**Hint:** The => is the lambda operator.

### 12. What is the difference between LINQ query syntax and method syntax?

- They are two ways to write the same queries; the compiler translates query syntax into method calls.
- Query syntax runs on the database while method syntax runs in memory.
- Method syntax cannot use where or select.
- Query syntax is faster at runtime.

**Hint:** One is syntactic sugar for the other.

### 13. What is deferred execution in LINQ?

- A query is not run until you enumerate its results, for example with foreach or ToList().
- A query always runs on a background thread.
- A query result is cached forever after the first run.
- A query executes immediately when defined.

**Hint:** When exactly does the loop over the data happen?

### 14. Which LINQ operator returns the number of elements?

- Count()
- Select()
- Where()
- OrderBy()

**Hint:** Which one forces the query to run and gives a number?

### 15. What does the await keyword do?

- It asynchronously waits for a Task to complete without blocking the calling thread.
- It blocks the current thread until the task finishes.
- It starts a new thread for every call.
- It converts a Task into a value type.

**Hint:** The whole point is to not block.

### 16. What is the difference between Task and Task<T>?

- Task represents an async operation with no result; Task<T> represents one that produces a value of type T.
- Task<T> runs synchronously while Task does not.
- Task cannot be awaited.
- They are identical.

**Hint:** One carries a return value, the other does not.

### 17. What is a CancellationToken used for?

- To signal that an asynchronous operation should be cancelled cooperatively.
- To forcibly kill a thread immediately.
- To cache the result of a task.
- To retry a failed task automatically.

**Hint:** Cancellation here is cooperative, not forced.

### 18. What does the CLR do?

- It is the runtime that executes .NET code, providing JIT compilation, garbage collection, and type safety.
- It is the C# compiler front end only.
- It is a package manager for .NET.
- It is a UI framework.

**Hint:** It is what actually runs your compiled program.

### 19. What is IL (Intermediate Language)?

- The CPU-independent bytecode that C# compiles to, which the CLR then JIT-compiles to native code.
- The native machine code for a specific processor.
- A configuration file format.
- A garbage-collection algorithm.

**Hint:** It sits between C# source and native code.

### 20. How does .NET garbage collection reclaim memory?

- It automatically frees objects that are no longer reachable, using a generational collector.
- It requires you to call free() on every object.
- It never runs until the program exits.
- It only collects value types.

**Hint:** Think generations: most objects die young.

### 21. What is an assembly in .NET?

- A compiled unit of code and resources, typically a .dll or .exe, that the CLR loads.
- A single source code file.
- A namespace declaration.
- A unit test project.

**Hint:** Think .dll or .exe.

### 22. What does the using statement (as in using var f = ...) guarantee?

- That Dispose() is called on the object when the block or scope ends, even if an exception is thrown.
- That the object is garbage collected immediately.
- That the object is thread-safe.
- That the object is never null.

**Hint:** It pairs with IDisposable.

### 23. What is a record type in modern C#?

- A reference (or value) type with built-in value-based equality and concise syntax, good for immutable data.
- A type that can only be used in databases.
- A mutable class with no equality support.
- A replacement for interfaces.

**Hint:** It compares by value, not by reference.

### 24. What does pattern matching with switch expressions provide?

- A concise way to branch on the shape or value of data and return a result.
- A way to define new types at runtime.
- Automatic multithreading.
- A replacement for garbage collection.

**Hint:** It is the => based switch that returns a value.

### 25. What is NuGet?

- The package manager for .NET, used to add and manage library dependencies.
- The .NET garbage collector.
- A UI design tool.
- The C# compiler.

**Hint:** It is how you pull in third-party libraries.

### 26. What is the role of the .csproj file?

- It defines the project: target framework, dependencies, and build settings.
- It stores compiled IL.
- It is the entry point method of the program.
- It is a runtime log file.

**Hint:** It is the project definition the dotnet CLI reads.
