MCTS .NET Application Development 2 — Questions and Answers
Question 1: Which .NET class is used to serialize an object to XML format?
- XmlSerializer (Correct answer)
- BinaryFormatter
- DataContractSerializer
- JsonSerializer
Correct answer: XmlSerializer
XmlSerializer converts objects to and from XML using public properties and fields.
Question 2: What is the purpose of the 'using' statement in C# when working with unmanaged resources?
- It imports a namespace
- It ensures Dispose() is called when the block exits (Correct answer)
- It declares a variable alias
- It creates a new thread context
Correct answer: It ensures Dispose() is called when the block exits
The 'using' statement guarantees that Dispose() is called on IDisposable objects even if an exception occurs.
Question 3: In ASP.NET, which HTTP module is responsible for Forms Authentication?
- WindowsAuthenticationModule
- FormsAuthenticationModule (Correct answer)
- SessionStateModule
- OutputCacheModule
Correct answer: FormsAuthenticationModule
FormsAuthenticationModule intercepts requests and redirects unauthenticated users to the login page.
Question 4: Which collection class in .NET provides O(1) lookup by key?
- List<T>
- Queue<T>
- Dictionary<TKey, TValue> (Correct answer)
- SortedList<TKey, TValue>
Correct answer: Dictionary<TKey, TValue>
Dictionary<TKey, TValue> uses a hash table internally, providing constant-time average lookups.
Question 5: What does the 'sealed' keyword prevent in C#?
- A class from being instantiated
- A class from being inherited (Correct answer)
- A method from being overridden in the same class
- A field from being modified
Correct answer: A class from being inherited
The sealed keyword prevents other classes from deriving from the marked class.
Question 6: In .NET, what is the role of the Common Language Runtime (CLR)?
- It compiles C# source code to IL
- It manages execution, memory, and security for .NET applications (Correct answer)
- It provides the .NET base class library
- It handles HTTP requests in ASP.NET
Correct answer: It manages execution, memory, and security for .NET applications
The CLR is the execution engine that handles memory management, JIT compilation, garbage collection, and security.
Question 7: Which ADO.NET object is used to execute a stored procedure and retrieve a result set?
- SqlConnection
- SqlDataAdapter
- SqlCommand (Correct answer)
- DataSet
Correct answer: SqlCommand
SqlCommand executes SQL statements or stored procedures and can return results via ExecuteReader or ExecuteScalar.
Which .NET class is used to serialize an object to XML format?