أسئلة القسم

تدرب على أسئلة المقابلات في هذا القسم. اكتب إجابتك، قم بتقييمها، أو اضغط على "عرض الإجابة" بعد التفكير.

What is the difference between Array, ArrayList, and List<T>? متوسط
Feature Array ArrayList (non-generic) List (generic)
Type safety Strongly typed Stores object → boxing/unboxing Strongly typed (generic)
Size Fixed Dynamic resizing Dynamic resizing
Performance Fastest (no overhead) Slower due to boxing/unboxing Better than ArrayList
Usage Simple, fixed size Legacy, avoid in new code Preferred in modern .NET
What is the difference between List<T> and LinkedList<T>? متوسط
Feature List (Array-backed) LinkedList (Nodes)
Memory layout Contiguous array Nodes linked with pointers
Access time O(1) by index O(n) by index
Insert/Delete O(n) in middle, O(1) at end O(1) if node reference known
Use case Frequent reads, index access Frequent inserts/deletes
What is the difference between Dictionary<TKey,TValue> and Hashtable? متوسط
Feature Dictionary<TKey,TValue> Hashtable
Type safety Generic → strongly typed Stores as object (boxing/unboxing)
Performance Faster (no boxing) Slower for value types
Thread safety Not thread-safe by default Some synchronization support
Usage Preferred in .NET Core Legacy, avoid in new code
When would you use SortedDictionary vs SortedList? متوسط

SortedDictionary<TKey, TValue>

  • Backed by a binary search tree (red-black tree).
  • Better for frequent inserts/deletes.

SortedList<TKey, TValue>

  • Backed by arrays.
  • Better for smaller collections and frequent lookups.
What is the difference between IEnumerable and IEnumerator? متوسط
  • IEnumerable: Represents a collection that can be iterated. Provides GetEnumerator().
  • IEnumerator: Represents the enumerator that actually iterates. Provides MoveNext(), Current, Reset().
How does Dictionary<TKey, TValue> handle key collisions? متوسط
  • Uses a hash code of the key → bucket index.
  • If multiple keys map to same bucket:
    • Uses equality comparer (Equals) to differentiate.
    • Stores colliding items in linked entries.
  • In .NET Core, collisions are resolved with chaining.
What is a delegate? متوسط

A delegate is a type-safe reference to a method.

  • Supports callback mechanisms, event handling, LINQ expressions.
What is Serialization? متوسط

Serialization: Converting an object into a format (JSON, XML, binary) to store or transfer.

  • Example: Save object to a file or send over network.
What is DeSerialization? متوسط

Converting serialized data back into an object.

What's the difference between XmlDocument and XmlReader? متوسط
Feature XmlDocument XmlReader
Model DOM (loads entire XML tree in memory) Forward-only reader
Memory High (whole doc) Low (reads node by node)
Usage Easy to navigate, modify Efficient for large XML
Performance Slower for big XML Faster, streaming-based
What are ref, out, and in parameters? متوسط
  • ref → Passes variable by reference (must be initialized before).
  • out → Passes variable by reference, but must be assigned inside method.
  • in → Passes by reference but as readonly (cannot modify inside method).
What is the difference between value parameter and ref parameter? متوسط

Value parameter (default):

  • A copy of the argument is passed.
  • Changes inside the method don’t affect the original variable.

Ref parameter:

  • Passes reference to the original variable.
  • Must be initialized before passing.
  • Changes inside the method affect the caller.
What is the difference between is and as operators? متوسط
  • is: Checks type compatibility, returns true/false.
  • as: Attempts safe cast, returns null if it fails (no exception).
What is boxing and unboxing in C#? متوسط
  • Boxing: Converting a value type → object (heap allocation).
  • Unboxing: Extracting value type from object.
What are iterators and the yield keyword? متوسط
  • Iterator: A method that returns elements one at a time (lazy evaluation).
  • yield return: Produces a value and remembers state for next iteration.
  • yield break: Ends iteration.
What is a Tuple and how is it different from an anonymous type? متوسط
  • Tuple: Lightweight data structure, supports multiple values. Mutable.
    • Example: var t = Tuple.Create(1, "Book");
  • Anonymous type: Compiler-generated class, read-only properties, scoped to method.
    • Example: var obj = new ;
  • Key difference: Tuples are reusable return types, anonymous types are method-scoped.
What are records in C# 9+ ? متوسط

Records are reference types introduced in C# 9, optimized for immutable, value-based equality.

What is the difference between records and classes? متوسط
Feature Class Record
Equality Reference equality by default Value equality (compares properties)
Immutability Mutable by default Init-only setters (encourage immut.)
Use case Represent entities Represent data models (DTOs, configs)
What is JIT compilation? متوسط

JIT (Just-In-Time) compiles IL (Intermediate Language) to machine code at runtime.

Types:

  • Pre-JIT (NGen/AOT): whole assembly ahead of time.
  • Econo-JIT: compiles only needed methods, discards unused.
  • Normal JIT: compiles as methods are called.
What is the app domain? متوسط

AppDomain: an isolation unit for .NET apps within a process.

  • Used to load/unload assemblies without restarting the process.
  • In .NET Core/.NET 5+, AppDomains are not supported → replaced with AssemblyLoadContext.
What are nullable types? متوسط
  • Value types (int, bool) cannot be null by default.
  • Nullable types (int?): wrap them in Nullable.
  • Provides HasValue and Value.
In .NET, what exactly is the High Frequency Heap? متوسط
  • A GC heap segment optimized for small, frequently allocated objects.
  • Introduced with Server GC in .NET 5+.
  • Reduces contention by giving each thread its own heap segment.
How does the garbage collector work in .NET? متوسط
  • Generational GC: objects are grouped into Gen 0, Gen 1, Gen 2.
  • Process:
    • Allocations go to Gen 0.
    • Short-lived → collected quickly.
    • Surviving objects promoted to higher generations.
    • Uses mark-and-sweep with compaction.
What is the difference between synchronous and asynchronous methods? متوسط
  • Synchronous: blocks until operation completes.
  • Asynchronous: frees the thread, continues when operation completes (non-blocking).
What are async/await and how do they improve performance? متوسط
  • async/await: syntactic sugar for working with Task.
  • Improves responsiveness (UI not blocked, server scales better).
  • Doesn’t create new threads (uses I/O completion).
How do you prevent two threads from accessing the same method? متوسط

Use synchronization primitives:

  • lock (monitor).
  • Mutex, SemaphoreSlim, ReaderWriterLockSlim.
When would you use the lock keyword? متوسط
  • When multiple threads access shared state.
  • Ensures only one thread executes a block at a time.