How do you declare and initialize a fixed-size array in C#?
Arrays in C# have a fixed size set at creation time, declared with square brackets after the element type, and can be initialized with a collection expression or explicit 'new' syntax.
The 50 C# questions worth preparing first, picked from all 296 on W3Teacher and spread across 24 topics. Each one has a short answer here and a full answer with examples and follow-ups on its own page.
Arrays in C# have a fixed size set at creation time, declared with square brackets after the element type, and can be initialized with a collection expression or explicit 'new' syntax.
await asynchronously waits for a Task, releasing the thread until it completes, then resumes the method; async marks a method that uses await and returns a Task.
An attribute is metadata attached to a code element (class, method, property, etc.) using square-bracket syntax placed directly above it — attributes don't affect runtime behavior on their own, but tools, frameworks, and your own reflection code can read them to alter behavior…
Use an array for a fixed-size, performance-critical buffer; use List when the count changes, since it grows and offers Add/Remove/Insert.
A delegate is a type-safe reference to a method, letting you pass behaviour as a parameter and invoke it later. Func<>, Action<> and Predicate<> are built-in delegates.
Dependency injection means a class RECEIVES its dependencies (typically via constructor parameters) from an external source, rather than constructing them itself with 'new' — this decouples the class from specific implementations, making it far easier to swap implementations…
Lazy defers creation of the instance until it's first accessed AND guarantees thread-safe initialization by default, making it the cleanest modern way to implement a Singleton without manually writing double-checked locking.
An enum is a distinct value type representing a named set of constant integral values; by default, its members are backed by 'int', starting at 0 and auto-incrementing, unless you assign explicit values.
For a reference type without overrides, both == and the inherited Object.Equals() check REFERENCE equality — whether two variables point to the exact SAME object in memory — not whether their content/data is logically equivalent.
throw re-throws preserving the original stack trace; throw ex resets the stack trace to the current line, losing where the error really happened.
An extension method lets you 'add' new methods to an existing type (even one you don't own the source for, like a built-in .NET type) without modifying it — declared as a static method in a static class, with the FIRST parameter prefixed with 'this', specifying which type it…
File.ReadAllText() reads an entire file's contents into a single string; File.WriteAllText() writes a string to a file, creating it if it doesn't exist or overwriting it if it does — both are synchronous and load the ENTIRE file into memory at once, fine for small files.
var uses compile-time type inference; the compiler still gives it a single static type. It is not dynamic — the type is fixed once inferred.
Generics let you write type-parameterised classes/methods that work with any type while keeping compile-time type safety and avoiding boxing.
An indexer is a special property-like member defined with 'this[...]' syntax, letting instances of your class be accessed using square brackets (obj[key]) just like an array or dictionary — you define get/set accessors just as with a normal property.
An abstract class can hold state and shared implementation and supports single inheritance; an interface is a contract a type can implement many of. Use interfaces for capabilities, abstract classes for a shared base.
'yield return' produces one value at a time from a sequence WITHOUT computing and storing the entire sequence upfront — the method's return type must be IEnumerable (or IEnumerator ), and the compiler transforms it into a state machine that pauses execution at each yield and…
LINQ queries collections and data sources uniformly. Most operators are lazy: the query executes when enumerated (foreach/ToList), so it reflects the latest data.
The GC automatically reclaims unreachable managed objects. It is generational (Gen 0/1/2): short-lived objects are collected cheaply in Gen 0, survivors are promoted.
Top-level statements (C# 9+) let you write executable code directly at the top of a .cs file WITHOUT wrapping it in an explicit Main() method or even a class — the compiler automatically generates the boilerplate Program class and Main method behind the scenes, reducing a…
An opt-in compiler feature where reference types are non-null by default and nullability is expressed with ?, giving warnings when you might dereference null.
Encapsulation (hide state behind members), Inheritance (derive types), Polymorphism (one interface, many implementations) and Abstraction (expose essentials, hide detail).
A record is a reference type with compiler-generated value equality, ToString and non-destructive mutation (with). It's ideal for immutable data.
Value types (struct, enum, primitives) hold their data directly and are copied on assignment; reference types (class, array, string, delegate) hold a reference to data on the heap, so assignment copies the reference.
A rectangular array (int[,]) has a fixed grid shape where every row has the same length; a jagged array (int[][]) is an array of arrays, where each inner array can have a different length, offering more flexibility at the cost of an extra indirection.
Task represents async work with no result; Task completes with a value of type T that you get by awaiting it.
Reflection lets you inspect metadata about types, methods, properties, and assemblies AT RUNTIME, even for types you don't have compile-time knowledge of — a Type object (obtained via typeof() or GetType()) exposes its name, properties, methods, constructors, and more.
When you need fast key-based lookups (O(1) average). Keys are unique; use TryGetValue to avoid exceptions on missing keys.
Func returns a value; Action returns void; Predicate is a Func used for tests.
Register a service's interface-to-implementation mapping in Program.cs using builder.Services.AddXxx(), then ASP.NET Core automatically INJECTS it into any controller or class constructor that declares a dependency on that interface — you never call 'new' or manually resolve it…
A Factory Method encapsulates object-creation logic behind a method (often on a base class or interface) that subclasses or implementations override to decide WHICH concrete type to instantiate — this decouples the calling code from needing to know or reference specific concrete…
Cast directly with (int) to get the numeric value; use ToString() to get the member's name as a string, and Enum.Parse () (or the safer Enum.TryParse ()) to convert a string back into the corresponding enum value.
System.ValueType (the base for all structs) overrides Equals() to perform FIELD-BY-FIELD value comparison by default (via reflection, which is slower than a hand-written override), unlike a plain class which defaults to reference equality — so two structs with identical field…
finally always runs (whether or not an exception occurred) and is used to release resources like files, connections or locks.
Extension methods are purely a COMPILE-TIME convenience — the compiler resolves 'obj.ExtensionMethod()' by rewriting it internally as 'StaticClass.ExtensionMethod(obj)', which requires the method to live in a static class; at runtime, there's no real difference from calling an…
File.ReadAllLines() reads the ENTIRE file and returns a fully-materialized string[] array all at once; File.ReadLines() returns a LAZY IEnumerable that reads and yields one line at a time as you iterate, using far less memory for very large files since it never holds the whole…
const is a compile-time constant embedded into callers and must be initialised inline; readonly is set once at runtime (declaration or constructor) and can vary per instance.
Declare a 'public static' method named 'operator +' taking two parameters of your type (or your type and another compatible type), returning the result — the compiler then lets you use the normal '+' syntax directly on instances of your type.
Depending on an abstraction decouples callers from implementations, enabling substitution, testing with mocks, and dependency injection.
Code inside an iterator method DOESN'T run at all when you first call it — it only executes incrementally, ONE STEP AT A TIME, as the consumer actually requests each next value (via foreach or manual MoveNext() calls) — meaning side effects (like Console.WriteLine) inside the…
Managed resources are handled by the GC; unmanaged resources (file handles, sockets, native memory) are not and must be released via Dispose/finalizers.
A file-scoped namespace (`namespace MyApp.Services;` with a semicolon, no braces) applies to EVERY type declared in the rest of that file, eliminating one level of nested indentation compared to the traditional `namespace MyApp.Services { ...
! tells the compiler you know a value isn't null, suppressing the warning. Use it sparingly when you have knowledge the compiler lacks — overuse hides real bugs.
Properties expose get/set accessors over a private field, letting you validate on set and compute on get while keeping the field hidden.
with creates a copy of a record with some properties changed, leaving the original unchanged (non-destructive mutation).
Local value types typically live on the stack; reference-type objects live on the managed heap with the reference on the stack. Value-type fields inside a class live on the heap with the object.
Span is a stack-only (ref struct) type representing a contiguous, type-safe view over a region of memory — it lets you slice arrays, strings, or stack-allocated memory WITHOUT copying data, avoiding the allocation overhead of creating new sub-arrays or substrings for temporary…
Constraints (where T : ...) restrict the type argument so you can use its members — e.g. class, struct, new(), a base type, or an interface.
IEnumerable executes in memory (LINQ-to-Objects); IQueryable builds an expression tree a provider (EF Core) translates to SQL, so filtering happens in the database.
Start the tasks without awaiting each immediately, then await Task.WhenAll to run them in parallel and wait for all.
Run a timed C# mock interview: random questions, answer out loud, reveal the model answer and get a readiness score you can share.