Runtime Basics
In the .NET platform, which statement best describes the Common Language Runtime (CLR) that executes your managed code when you press the run button in an IDE?
- It manages memory, enforces type safety, and executes managed code.
- It is a version control system for tracking code changes.
- It is a markup language used to design web pages.
- It only compiles native C++ code and ignores managed code.
- It is a relational database engine for storing tables.
Exception Handling Keyword
When reading a file that might not exist, which C# keyword pairs with a try block to handle any exception that could be thrown?
- catch
- throw
- final
- rescue
- except
Boxing Definition
In C#, what is the term for converting a value type such as int to an object reference, for example int x = 5; object o = x; ?
- Boxing
- Unboxing
- Casting
- Marshalling
- Pinning
Generic List Characteristics
Which generic collection in C# allows zero-based indexing, preserves insertion order, and allows duplicate items, for example storing [2, 2, 3] and accessing items by index?
- Listu003CTu003E
- HashSetu003CTu003E
- Dictionaryu003CTKey,TValueu003E
- SortedSetu003CTu003E
- Queueu003CTu003E
Asynchronous Methods
When creating an asynchronous method that returns Task, which C# keyword must be in the method signature to enable the use of await inside it?
- async
- await
- yield
- defer
- future
Interfaces vs Abstract Classes
When designing a plugin system where classes may already inherit from another base class, which statement about interfaces and abstract classes in C# is correct?
- A class can implement multiple interfaces, which only declare members without state.
- An abstract class can be instantiated directly if all abstract members are implemented.
- A class can inherit from multiple abstract classes.
- Interfaces can contain instance fields that hold state by default.
- Interfaces cannot be used as method parameter types.
Access Modifiers
Which access modifier in C# makes a field visible only within the class it is declared in, for example hiding a balance field from other classes?
- private
- protected
- internal
- public
- privet
Using Statement Behavior
When opening a file stream with using (var fs = ...), what does the using statement ensure even if an exception occurs?
- Dispose is called automatically on the object when the block exits.
- The object is pinned and cannot be moved by the garbage collector.
- All exceptions inside the block are ignored.
- The file is kept open after the block for reuse.
- The code inside the block runs on a background thread.
Type Inference with var
In the statement var count = 10;, which best describes what var means in C#?
- The compiler infers the specific type at compile time.
- The variable can change its type at runtime.
- It is always of type object regardless of the assigned value.
- It creates a dynamic type that bypasses compile-time checking.
- It automatically makes the variable nullable.
LINQ Filtering
Given an array numbers = new[] { 1, 2, 3, 4, 5 }, which LINQ method would you call to return only the even numbers?
- Where
- Select
- OrderBy
- GroupBy
- Join