NewWork mode: your Claude Code or Codex on work calls, answering from your project's codeSkip to content

Quiz: C#

C# questions from real interviews as a quiz, with an explanation for every option.

37 questionsAll topicsC#

Try it: 5 questions

Loading…

Sample questions

  1. Which statements about searching in List<T> and Dictionary<TKey, TValue> in C# are correct?

    • Looking up a key in Dictionary<TKey, TValue> always takes O(1), even when there are many collisions.
    • Dictionary<TKey, TValue> searches for keys with binary search in a sorted array.
    • Searching for an element in List<T> usually takes O(n).
    • A Dictionary hashes the key, selects a bucket, and resolves collisions by comparing keys.
    • Looking up a key in Dictionary<TKey, TValue> takes O(1) on average.
    Full answer
  2. What does the IEnumerable interface provide in C#?

    • Index-based access to elements
    • A guarantee that elements are loaded lazily
    • Methods for adding and removing elements
    • A way to iterate over elements using GetEnumerator()
    Full answer
  3. CalendarService.IsWorkingDay() checks DateTime.Now.DayOfWeek, but the test always expects true. What is the main problem with the test, and how can it be made reliable?

    • It checks only the result; replace Assert.True with Assert.Equal(true, actual).
    • The service is created incorrectly; create a new CalendarService for each day of the week.
    • The method should return true every day, so remove the weekend check from the service.
    • It can fail on weekends; control the time source and test multiple days of the week.
    Full answer
  4. How does the System namespace relate to .NET assemblies?

    • Each of its types must reside in a separate DLL.
    • It is a logical grouping; its types can reside in multiple assemblies.
    • It is always implemented entirely in one DLL.
    • It combines types from only one source assembly.
    Full answer
  5. How do the try, catch, and finally blocks work in C#?

    • try contains code that may fail, catch handles a matching exception, and finally runs after try and catch whether or not an exception occurred.
    • try contains code, catch runs only when no exception occurs, and finally runs only when one does.
    • try checks code for errors before execution, catch fixes any errors it finds, and finally runs the code again.
    • try handles exceptions, catch always runs after it, and finally runs only if no exception occurred.
    Full answer
  6. Which statements correctly explain why BULK INSERT can load data faster than ordinary row-by-row inserts? Select all that apply.

    • BULK INSERT completely disables transaction logging.
    • When the requirements are met, SQL Server can use minimal logging.
    • BULK INSERT always disables the table's indexes, so it does not spend time maintaining them.
    • Loading large batches and deferring index maintenance until after the load can reduce overhead.
    • Under suitable conditions, such as with TABLOCK, SQL Server can perform the load in parallel.
    Full answer
  7. Can C# value types be allocated on the managed heap?

    • Yes, but only if the struct exceeds a certain size limit.
    • No, all value types are always allocated on the stack.
    • Yes, but only when boxed; they cannot be fields of class objects.
    • Yes, for example, as a field of a class object or when boxed.
    Full answer
  8. In C#, what happens when you assign a value using a key that is already present in a Dictionary?

    • A new key is created with its value changed automatically.
    • The value for that key is replaced.
    • A second entry with the same key is added.
    • The operation always throws an exception.
    Full answer
  9. What does RPS measure, and what can happen if a system cannot keep up as it rises?

    • Requests handled per second; latency may rise and requests may be lost.
    • The size of the database; an increase means more disk space is needed.
    • Average response time; as RPS rises, latency always decreases.
    • The number of concurrent users; a high RPS guarantees there is no overload.
    Full answer
  10. What does the Unit of Work pattern do, and which category is it usually associated with?

    • Creates an object with the required configuration; it is a GoF creational pattern.
    • Provides a unified interface to a complex subsystem; it is a GoF structural pattern.
    • Tracks changes within an operation and saves them together; it is an Enterprise Application Architecture pattern.
    • Synchronizes concurrent threads accessing data; it is a concurrency pattern.
    Full answer