Q1. - (Topic 2)
You are creating an application that reads from a database.
You need to use different databases during the development phase and the testing phase by using conditional compilation techniques.
What should you do?
A. Configure the assembly metadata to use the pre-existing public key for the assembly identity by using the AssemblySignatureKeyAttribute attribute.
B. Disable the strong-name bypass feature of Microsoft .NET Framework in the registry.
C. Configure the Define DEBUG constant setting in Microsoft Visual Studio.
D. Decorate the code by using the [assembly:AssemblyDelaySignAttribute(true)] attribute.
Answer: C
Explanation: Use one debug version to connect to the development database, and a standard version to connect to the live database.
Q2. - (Topic 2)
You have a class named Customer and a variable named customers.
You need to test whether the customers’ variable is a generic list of Customer objects. Which line of code should you use?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: D
Explanation:
http://stackoverflow.com/questions/982487/testing-if-object-is-of-generic-type-in-c-sharp
Q3. DRAG DROP - (Topic 2)
You are creating a method that saves information to a database.
You have a static class named LogHelper. LogHelper has a method named Log to log the exception.
You need to use the LogHelper Log method to log the exception raised by the database server. The solution must ensure that the exception can be caught by the calling method, while preserving the original stack trace.
How should you write the catch block? (Develop the solution by selecting and ordering the required code snippets. You may not need all of the code snippets.)
Answer:
Q4. - (Topic 1)
An application includes a class named Person. The Person class includes a method named GetData.
You need to ensure that the GetData() method can be used only by the Person class and not by any class derived from the Person class.
Which access modifier should you use for the GetData() method?
A. Public
B. Protected internal
C. Internal
D. Private
E. Protected
Answer: D
Explanation:
The GetData() method should be private. It would then only be visible within the Person class.
Q5. - (Topic 2)
You are developing a C# application. The application references and calls a RESTful web service named EmployeeService. The EmployeeService web service includes a method named GetEmployee, which accepts an employee ID as a parameter. The web service returns the following JSON data from the method.
{"Id":1,"Name":"David Jones">
The following code segment invokes the service and stores the result:
You need to convert the returned JSON data to an Employee object for use in the application.
Which code segment should you use?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: C
Q6. - (Topic 2)
You have the following code (line numbers are included for reference only):
You need to ensure that if an exception occurs, the exception will be logged. Which code should you insert at line 28?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: A
Explanation: * XmlWriterTraceListener
Directs tracing or debugging output as XML-encoded data to a TextWriter or to a Stream,
such as a FileStream.
Q7. - (Topic 1)
You are creating a class named Game.
The Game class must meet the following requirements:
Include a member that represents the score for a Game instance.
Allow external code to assign a value to the score member.
Restrict the range of values that can be assigned to the score member.
You need to implement the score member to meet the requirements.
In which form should you implement the score member?
A. protected field
B. public static field
C. public static property
D. public property
Answer: D
Q8. - (Topic 1)
You are creating an application that manages information about your company's products. The application includes a class named Product and a method named Save.
The Save() method must be strongly typed. It must allow only types inherited from the Product class that use a constructor that accepts no parameters.
You need to implement the Save() method. Which code segment should you use?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: D
Explanation:
When you define a generic class, you can apply restrictions to the kinds of types that client
code can use for type arguments when it instantiates your class. If client code tries to instantiate your class by using a type that is not allowed by a constraint, the result is a compile-time error. These restrictions are called constraints. Constraints are specified by using the where contextual keyword. http://msdn.microsoft.com/en-us/library/d5x73970.aspx
Q9. - (Topic 2)
You are developing an application that uses several objects. The application includes the following code segment. (Line numbers are included for reference only.)
You need to evaluate whether an object is null. Which code segment should you insert at line 03?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: B
Explanation: Use the == operator to compare values and in this case also use the null literal.
Q10. HOTSPOT - (Topic 1)
You are implementing a library method that accepts a character parameter and returns a string.
If the lookup succeeds, the method must return the corresponding string value. If the lookup fails, the method must return the value "invalid choice."
You need to implement the lookup algorithm.
How should you complete the relevant code? (To answer, select the correct keyword in each drop-down list in the answer area.)
Answer:
Q11. - (Topic 2)
You write the following method (line numbers are included for reference only):
You need to ensure that the method extracts a list of URLs that match the following pattern: @http://(www\.)?([^\.]+)\.com;
Which code should you insert at line 07?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: D
Explanation: * MatchCollection Represents the set of successful matches found by iteratively applying a regular expression pattern to the input string. The collection is immutable (read-only) and has no public constructor. The Regex.Matches method returns a MatchCollection object.
* List<T>.Add Method Adds an object to the end of the List<T>. Incorrect: Not A: ICollection.SyncRoot Property For collections whose underlying store is not publicly available, the expected implementation is to return the current instance. Note that the pointer to the current instance might not be sufficient for collections that wrap other collections; those should return the underlying collection's SyncRoot property.
Q12. - (Topic 2)
You are developing an application that includes a class named Customer and a generic list of customers. The following code segment declares the list of customers:
List<Customer> customersList = new List<Customer> () ;
You populate the customersList object with several hundred Customer objects.
The application must display the data for five Customer objects at a time.
You need to create a method that will return the correct number of Customer objects.
Which code segment should you use?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: A
Q13. - (Topic 2)
You are writing the following method (line numbers are included for reference only):
You need to ensure that CreateObject compiles successfully.
What should you do?
A. Insert the following code at line 02: where T : new()
B. Replace line 01 with the following code: public void CreateObject<T>()
C. Replace line 01 with the following code: public Object CreateObject<T>()
D. Insert the following code at line 02: where T : Object
Answer: A
Q14. - (Topic 2)
You have the following code (line numbers are included for reference only):
You need to ensure that new instances of Connection can be created only by other classes by calling the Create method. The solution must allow classes to inherit from Connection.
What should you do?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: B
Explanation: The following list provides the main features of a static class:
* Contains only static members.
* Cannot be instantiated.
* Is sealed.
* Cannot contain Instance Constructors.
Creating a static class is therefore basically the same as creating a class that contains only static members and a private constructor. A private constructor prevents the class from being instantiated.
Reference: Static Classes and Static Class Members (C# Programming Guide)
https://msdn.microsoft.com/en-us/library/79b3xss3.aspx
Q15. - (Topic 1)
You are developing an application that includes the following code segment. (Line numbers are included for reference only.)
The GetCustomers() method must meet the following requirements:
Connect to a Microsoft SQL Server database.
Populate Customer objects with data from the database.
Return an IEnumerable<Customer> collection that contains the populated
Customer objects.
You need to meet the requirements.
Which two actions should you perform? (Each correct answer presents part of the solution. Choose two.)
A. Insert the following code segment at line 17: while (sqlDataReader.GetValues())
B. Insert the following code segment at line 14: sqlConnection.Open();
C. Insert the following code segment at line 14: sqlConnection.BeginTransaction();
D. Insert the following code segment at line 17: while (sqlDataReader.Read())
E. Insert the following code segment at line 17: while (sqlDataReader.NextResult())
Answer: B,D
Explanation:
SqlConnection.Open - Opens a database connection with the property settings specified by the ConnectionString.
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.open.aspx SqlDataReader.Read - Advances the SqlDataReader to the next record. http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.read.aspx