MCTS .NET Application Development 3 — Questions and Answers
Question 1: Which design pattern does the .NET event model implement?
- Factory
- Observer (Correct answer)
- Strategy
- Decorator
Correct answer: Observer
The Observer pattern defines a one-to-many dependency, and .NET events/delegates implement this pattern directly.
Question 2: What is the difference between 'ref' and 'out' parameters in C#?
- ref requires initialization before the call; out does not (Correct answer)
- out requires initialization before the call; ref does not
- ref is for value types only; out is for reference types only
- There is no difference — they are interchangeable
Correct answer: ref requires initialization before the call; out does not
A ref parameter must be assigned before being passed, while an out parameter must be assigned within the called method.
Question 3: Which ASP.NET Web Forms control renders an HTML <table> and supports paging and sorting?
- Repeater
- DataList
- GridView (Correct answer)
- FormView
Correct answer: GridView
GridView renders tabular data with built-in support for paging, sorting, and editing.
Question 4: In .NET threading, what does the 'lock' keyword do?
- Prevents a thread from starting
- Acquires a mutual-exclusion lock on an object to synchronize access (Correct answer)
- Marks a method as thread-safe automatically
- Suspends all other threads indefinitely
Correct answer: Acquires a mutual-exclusion lock on an object to synchronize access
The lock statement acquires a monitor lock, ensuring only one thread can execute the enclosed block at a time.
Question 5: What is the purpose of the Global.asax file in an ASP.NET application?
- It stores connection strings
- It handles application-level and session-level events (Correct answer)
- It defines URL routing rules
- It configures HTTP modules and handlers
Correct answer: It handles application-level and session-level events
Global.asax contains event handlers for application lifecycle events such as Application_Start and Session_Start.
Question 6: Which interface must a class implement to support foreach iteration in C#?
- IComparable
- IDisposable
- IEnumerable (Correct answer)
- ICloneable
Correct answer: IEnumerable
IEnumerable exposes GetEnumerator(), which the foreach statement uses to iterate over a collection.
Question 7: In .NET, what is boxing?
- Converting a reference type to a value type
- Converting a value type to an object reference type (Correct answer)
- Casting a derived class to a base class
- Wrapping an exception in another exception
Correct answer: Converting a value type to an object reference type
Boxing wraps a value type (e.g., int) inside an object on the heap so it can be treated as a reference type.
Which design pattern does the .NET event model implement?