All questions
Showing of 112Explain the difference between value types and reference types in C#.
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
A value type holds its data directly, while a reference type holds a reference to an object on the heap. Assigning a value type copies the whole value, and assigning a reference type copies only the reference.
Changing one copy of a value type leaves the other copy alone. Two reference-type variables can point at the same object, so a change made through one shows up through the other.
- Value types include
int,boolandchar. Everystructandenumis a value type too. - Reference types include any
classandstring. Arrays and delegates are reference types too.
Value types default to zero, false or null in every field. Reference types default to null.
A local value-type variable usually sits on the stack, but a value-type field lives inside its containing object, on the heap.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is the difference between const and readonly in C#?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
A const is fixed at compile time, while a readonly field is fixed at run time, when its object or type is initialized.
- A
constmust be initialized where it is declared and never changes. It is implicitlystaticand holds only primitive types, string literals ornull. - A
readonlyfield is set in its declaration or a constructor, so each instance can get its own value. It can be instance orstaticand hold any type.
For a reference type, readonly fixes only the reference. The object it points to can still change.
The compiler copies a const value into every caller, so changing it means recompiling those callers. A readonly value is read at run time. Use const for values that never change between versions, and readonly for values known only at run time.
public class Example
{
const int MAX_SIZE = 100; // Compile-time constant
readonly DateTime createdDate; // Runtime constant
public Example()
{
createdDate = DateTime.Now; // Can set in constructor
}
}
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What are namespaces in C# and why are they important?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
A namespace groups related types under a name, such as MyCompany.DataAccess, so two types can share a name without clashing.
Namespaces are hierarchical. That lets you organize a codebase by area and keeps type names short and readable. Code refers to a type by its full name, or imports the namespace with a using directive.
namespace MyCompany.DataAccess
{
public class DatabaseConnection { }
}
namespace MyCompany.UI
{
public class DatabaseConnection { } // Same name, different namespace
}
Namespaces only affect names. They do not control loading, because the runtime loads code by assembly, and one assembly can hold many namespaces.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is the var keyword and when should you use it?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
var declares an implicitly typed local variable, whose type the compiler infers from the initializer. The variable is still strongly typed, and its type is fixed at compile time.
It only works for local variables initialized where they are declared. Use it when the type is obvious from the right side, like new List<int>(). It is required for anonymous types, which have no name you can write. It also shortens LINQ queries with long type names. Avoid it when the type is not clear from the code.
var number = 42; // int
var text = "Hello"; // string
var list = new List<int>(); // List<int>
// Required for anonymous types
var person = new { Name = "John", Age = 30 };
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
Explain the four pillars of Object-Oriented Programming.
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Encapsulation bundles data with its methods and hides the internals, and inheritance builds a new class from an existing one to reuse its code. Polymorphism lets code use different types through one common type, and abstraction shows only the essential features.
C# has a language feature for each pillar:
- For encapsulation, access modifiers like
private, plus properties. - For inheritance, a single base class, as in
class Car : Vehicle. - For polymorphism,
virtualandoverridemethods and interfaces. - For abstraction,
abstractclasses and interfaces.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
Explain method overriding vs method overloading.
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Overloading gives several methods one name with different parameters, and the compiler picks one at compile time. Overriding replaces a base class method in a derived class, and the runtime picks one based on the object's actual type.
The compiler chooses an overload from the argument types, so overloading is compile-time polymorphism. Overloads can live in the same class, like the two Add methods below. The return type alone cannot tell overloads apart.
Overriding needs virtual or abstract on the base method and override in the derived class. A Shape variable holding a Circle runs Circle.GetArea, so overriding is runtime polymorphism.
Use overloads for the same operation on different inputs. Use overriding to change behavior in a subclass.
// Overloading
public class Calculator
{
public int Add(int a, int b) { return a + b; }
public double Add(double a, double b) { return a + b; }
}
// Overriding
public class Shape
{
public virtual double GetArea() { return 0; }
}
public class Circle : Shape
{
private double radius;
public override double GetArea() { return Math.PI * radius * radius; }
}
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
Explain access modifiers in C#.
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Access modifiers control which code can use a type or member.
publicis accessible from anywhere.privateis accessible only inside the containing class.protectedis accessible in the class and its derived classes.internalis accessible anywhere in the same assembly.protected internalis accessible in the same assembly, or from derived classes in any assembly.private protectedis accessible only from derived classes in the same assembly.
Members of a class default to private, and top-level types default to internal. Pick the most restrictive one that works.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What are constructors and their types in C#?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
A constructor is a special method that runs when an object is created and sets up its state. It has the class name and no return type.
- A default constructor takes no parameters. The compiler adds one only when the class declares no constructor.
- A parameterized constructor takes values to initialize the object.
- A static constructor initializes static members. It runs once per type, before first use.
- A private constructor stops outside code from creating instances, as in a singleton.
- C# has no built-in copy constructor, so you write one yourself.
public class Person
{
// Parameterized constructor
public Person(string name, int age)
{
Name = name;
Age = age;
}
// Static constructor
static Person()
{
// Initialize static members
}
}
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What are nullable types and how do you use them?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
A nullable value type, written int?, lets a value type hold null as well as its normal values. It is shorthand for Nullable<int>, a struct with a HasValue flag and a Value property.
It fits data that can be missing, like a database column that allows NULL or an optional form field.
Check HasValue before reading Value, because reading Value when it holds nothing throws an InvalidOperationException. The ?? operator supplies a fallback instead, and GetValueOrDefault() returns the type's default.
int? nullableInt = null;
bool? nullableBool = null;
// Checking for null
if (nullableInt.HasValue)
{
int value = nullableInt.Value;
}
// Null coalescing operator
int result = nullableInt ?? 0; // Use 0 if null
Do not confuse these with nullable reference types like string?, which are compile-time annotations only.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
Explain the difference between string and StringBuilder.
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
A string is immutable, so every change creates a new string object. A StringBuilder is mutable and appends into an internal buffer, so repeated changes avoid those extra objects.
Concatenating in a loop shows the cost. Each += on a string copies all the text built so far, so the total work grows with the square of the length. StringBuilder keeps one buffer and only reallocates when its capacity runs out.
Use string for a few concatenations, where the difference is too small to matter. Use StringBuilder when you build text in a loop or across many steps.
Immutability also makes a string safe to share across threads. A StringBuilder is not thread-safe, so one thread should own it.
// Inefficient - creates multiple string objects
string result = "";
for (int i = 0; i < 1000; i++)
{
result += i.ToString(); // Creates new string each time
}
// Efficient - uses internal buffer
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 1000; i++)
{
sb.Append(i); // Modifies existing buffer
}
string result2 = sb.ToString();
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
Explain implicit and explicit type conversion.
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
An implicit conversion happens automatically because the compiler knows it is safe, like int to double. An explicit conversion needs a cast, like (int)largeValue, because the value may not fit.
Implicit conversions go from a smaller type to a larger one, so the value never overflows. They are not always exact, though. Converting int to float or long to double can lose precision, while keeping the magnitude.
Explicit conversions go from larger to smaller types, or between types that are not directly compatible. They can lose data, as when a cast drops the decimal part of a double. In a checked context they can also throw an OverflowException.
The Convert class handles conversions a cast cannot do, like turning the string "123" into an int.
// Implicit conversion
int intValue = 123;
double doubleValue = intValue; // Automatic conversion
// Explicit conversion
double largeValue = 123.456;
int smallValue = (int)largeValue; // Manual cast, loses decimal part
// Using Convert class
string numberString = "123";
int convertedValue = Convert.ToInt32(numberString);
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is the difference between Parse() and TryParse() methods?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Parse() returns the value and throws on invalid input, while TryParse() returns a bool for success and passes the value out through an out parameter.
Use Parse when invalid input means a bug, such as data your own code produced. Use TryParse for input you do not control, like user input or file contents. It avoids the cost of throwing and catching an exception for a failure you expect.
int.Parse throws a FormatException for text that is not a number, and an OverflowException when the number is out of range. On failure, TryParse sets the out value to its default, which is 0 for int. Most built-in value types have both methods, including DateTime and Guid.
// Parse - throws exception on failure
try
{
int value1 = int.Parse("123");
int value2 = int.Parse("abc"); // Throws FormatException
}
catch (FormatException ex) { }
// TryParse - safe conversion
if (int.TryParse("123", out int value3))
{
// Conversion successful
}
else
{
// Conversion failed, value3 is 0
}
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
Explain the difference between Array, ArrayList, and List<T>.
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
An array has a fixed size, while ArrayList and List<T> grow as you add items. Arrays and List<T> are type-safe, and ArrayList is not.
ArrayList stores everything as object. Adding an int boxes it, and nothing stops you mixing strings and numbers in one list. The mistake shows up at run time as a failed cast. List<T> is generic, so the compiler checks every Add, and at run time it stores value types without boxing.
| Array | ArrayList |
List<T> |
|
|---|---|---|---|
| Size | Fixed | Grows | Grows |
| Type-safe | Yes | No | Yes |
| Boxes value types | No | Yes | No |
| Use it for | Fixed-size data, best performance | Legacy code only | Most collections |
All three use zero-based indexing. Prefer List<T> in new code, and an array when the size is known and fixed.
// Array
int[] array = new int[5];
// ArrayList (avoid)
ArrayList arrayList = new ArrayList();
arrayList.Add(1); // Boxing occurs
arrayList.Add("text"); // No compile-time type checking
// List<T> (preferred)
List<int> list = new List<int>();
list.Add(1); // No boxing
// list.Add("text"); // Compile-time error
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What are the different types of generic collections in C#?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
The core generic collections are List<T>, Dictionary<TKey, TValue> and HashSet<T>, with queues, stacks and sorted versions for special cases. They live in System.Collections.Generic, are type-safe, and store value types without boxing.
List<T>is a dynamic array, andLinkedList<T>is a doubly linked list.HashSet<T>holds unique items with fast lookup, andSortedSet<T>keeps them sorted.Dictionary<TKey, TValue>maps keys to values with fast lookup, andSortedDictionary<TKey, TValue>keeps the keys sorted.Queue<T>is first in, first out, andStack<T>is last in, first out.
For shared access across threads, ConcurrentDictionary<TKey, TValue> in System.Collections.Concurrent is the thread-safe dictionary.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
Explain the try-catch-finally block structure.
What is LINQ and what are its benefits?
Explain the difference between query syntax and method syntax in LINQ.
What are lambda expressions and how are they used in LINQ?
What is the difference between anonymous methods and lambda expressions?
What is the difference between synchronous and asynchronous programming?
What is the difference between Task and Task<T>?
What is the difference between stack and heap memory?
What are extension methods and how do you create them?
Explain raw string literals in C# 11.
Explain global using directives and file-scoped namespaces.
Explain the differences between .NET Framework, .NET Core, and .NET 5+.
What is the difference between ref, out, and in parameters?
Explain anonymous types and their limitations.
What is the params keyword and how is it used?
Explain the using declaration vs using statement.
Explain tuple types and deconstruction.
What are switch expressions vs switch statements?
How do classes and structs differ, and when should you use a struct?
What is the difference between float, double and decimal in C#?
What is the difference between the is and as operators in C#?
What is the difference between Thread.Sleep and Task.Delay?
Explain indexers in C#.
Explain the concept of boxing and unboxing in C#.
Explain the difference between == operator and Equals() method.
What is the difference between abstract class and interface?
What is the difference between virtual, override, and new keywords?
What is the difference between composition and inheritance?
Explain the concept of sealed classes and methods.
What is string interning in C#?
What are generics and what are their benefits?
Explain generic constraints in C#.
What is the difference between IEnumerable and IEnumerator?
Explain the difference between IEnumerable<T> and IQueryable<T>.
What is the difference between throw and throw ex?
What are custom exceptions and when should you create them?
Explain the using statement and IDisposable interface.
What is deferred execution in LINQ?
Explain the difference between First(), FirstOrDefault() , Single(), and SingleOrDefault() .
Explain GroupBy in LINQ with an example.
What is the difference between Select and SelectMany?
Explain Join operations in LINQ.
What are delegates in C# and how do they work?
Explain the difference between Func, Action, and Predicate delegates.
What are events and how are they different from delegates?
Explain event handling patterns in C#.
Explain async and await keywords.
Explain ConfigureAwait(false) and when to use it.
What is the difference between Task.Run() and direct async method call?
Explain parallel programming with Task.WhenAll and Task.WhenAny.
What are the best practices for async/await?
How does garbage collection work in C#?
What are finalizers and destructors in C#?
Explain memory leaks in C# and how to prevent them.
What is reflection in C# and when would you use it?
Explain attributes in C# and provide examples.
Explain partial classes and partial methods.
What is the dynamic keyword and when should you use it?
Explain the yield keyword and iterators.
What are nullable reference types and how do they work?
Explain records in C# and their benefits.
What are pattern matching enhancements in modern C#?
Explain the required keyword in C# 11.
What are list patterns in C# 11?
What are UTF-8 string literals in C# 11?
What are primary constructors in C#, and what are their limitations?
What design patterns and idioms are common in C#?
What are common debugging and testing practices in C#?
Explain minimal APIs in .NET 6+.
What is dependency injection and how is it implemented in .NET?
Explain threading concepts: Thread, ThreadPool, and Task.
What are locks and synchronization in C#?
Explain the Repository and Unit of Work patterns.
What is operator overloading and how do you implement it?
What are local functions and when would you use them?
Explain the service lifetimes in the .NET dependency injection container and what a captive dependency is.
How do you support cancellation in async C# code with CancellationToken and CancellationTokenSource?
What is IAsyncEnumerable<T> and how does await foreach differ from returning Task<IEnumerable<T>>?
How would you design a thread-safe singleton in C#?
Should you ever call GC.Collect() manually?
What is the correct middleware order for routing, CORS, authentication, and authorization in ASP.NET Core?
Your endpoint returns 50 rows but the logs show 51 queries. What happened?
You see async void in a code review. Why do you flag it?
Why should you override GetHashCode whenever you override Equals?
What is System.Threading.Channels, and when is it better than ConcurrentQueue?
Explain security best practices in C#.
What actually happens when you call .Result or .Wait() on a Task?
Explain covariance and contravariance in generics.
Explain weak references and when to use them.
What is the stackalloc keyword and when should you use it?
Explain Span<T> and Memory<T> and their use cases.
What are ref structs and their limitations?
Explain generic math and static interface members in C# 11.
What are scoped variables and ref safety in C# 11?
Explain performance considerations and best practices in C#.
What are source generators and how do they work?
What are expression trees and how are they used?
What is ValueTask<T> and when should you use it instead of Task<T>?
This answer is part of Pro.
The full written answer, with the trade-offs and follow-ups an interviewer will probe.
No matches
Try a different filter or search term.
C# in pictures.
A quick recap of C# in 31 short animated pictures, one idea at a time. About 8 min to get the whole topic back in your head before you walk in. Pause any picture, slow it down, or step through it.
Pro The first chapter is free to play. The other 26 pictures come with Pro.
C# cheatsheet
- Types & values01
- Classes & records02
- Methods & pattern matching03
- Collections & generics04
- Delegates, events & LINQ05
- Async & await06
- Threads & locks07
- Errors & disposal08
- Memory & performance09
- ASP.NET Core & .NET10
- The model11
- + 5 more inside
This picture is part of Pro. The first chapter is free to play; the other 26 pictures come with Pro.
Get Pro · $10/mo Already Pro? Sign in98 of 112 C# answers are in Pro.
Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.
- Full answers + code
- AI explanations, simpler or deeper
- 1,000 AI credits / month
- Cancel anytime
Change topic
Pick a different technology or stack. Your current topic stays put until you choose a new one.
MEAN
MongoDB, Express, Angular, Node.jsMERN
MongoDB, Express, React, Node.jsDjango
Python Full-Stack DevelopmentRuby on Rails
Convention over ConfigurationServerless on AWS
Serverless Architecture on AWSInterviewers also test these - they're common to every stack, whichever one you picked above.
Flutter Mobile
Flutter Cross-Platform Mobile DevelopmentInterviewers also test these - they're common to every stack, whichever one you picked above.
Spring Boot
Enterprise Java Development.NET
Microsoft EcosystemVue
Vue.js, Vite, TypeScript, Tailwind, Node.jsGo Backend
Golang, gRPC, PostgreSQL, Redis, RabbitMQInterviewers also test these - they're common to every stack, whichever one you picked above.
FastAPI
Python, FastAPI, SQLAlchemy, PostgreSQLReact Native
React, TypeScript, Redux, FirebaseiOS Native
Swift, SwiftUI, UIKit, FirebaseAndroid Native
Java, Jetpack Compose, FirebaseDevOps / Platform
Docker, Kubernetes, Terraform, CI/CDInterviewers also test these - they're common to every stack, whichever one you picked above.
AI Engineer
LLMs, RAG, Agents, EvalsAI-Powered Developer
Claude Code, Copilot, Agentic WorkflowsCore SWE Interview Prep
Data structures, algorithms, OS, concurrency, networking, gitInterviewers also test these - they're common to every stack, whichever one you picked above.
Interviewers also test these - they're common to every stack, whichever one you picked above.