Q1. - (Topic 1)
You are developing an application that includes a class named BookTracker for tracking library books. The application includes the following code segment. (Line numbers are included for reference only.)
You need to add a book to the BookTracker instance. What should you do?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: A
Q2. - (Topic 2)
You have the following code:
You need to retrieve all of the numbers from the items variable that are greater than 80. Which code should you use?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: B
Explanation: Enumerable.Where<TSource> Method (IEnumerable<TSource>,
Func<TSource, Boolean>)
Filters a sequence of values based on a predicate.
Example:
List<string> fruits =
new List<string> { "apple", "passionfruit", "banana", "mango",
"orange", "blueberry", "grape", "strawberry" };
IEnumerable<string> query = fruits.Where(fruit => fruit.Length < 6);
foreach (string fruit in query)
{
Console.WriteLine(fruit);
}
/*
This code produces the following output:
apple
mango
grape */
Q3. DRAG DROP - (Topic 2)
You are developing a C# application. The application includes a class named Rate. The following code segment implements the Rate class:
You define a collection of rates named rateCollection by using the following code segment:
Collection<Rate> rateCollection = new Collection<Rate>() ;
The application receives an XML file that contains rate information in the following format:
You need to parse the XML file and populate the rateCollection collection with Rate objects.
You have the following code: Which code segments should you include in Target 1, Target 2, Target 3 and Target 4 to complete the code? (To answer, drag the appropriate code segments to the correct targets in the answer area. Each code segment may be used once, more than once, or not at all. You may need to drag the split bar between panes or scroll to view content.)
Answer:
Q4. - (Topic 2)
You need to store the values in a collection.
The solution must meet the following requirements:
. The values must be stored in the order that they were added to the collection. . The values must be accessed in a first-in, first-out order.
Which type of collection should you use?
A. SortedList
B. Queue
C. ArrayList
D. Hashtable
Answer: B
Q5. - (Topic 2)
You are developing an application that includes a method named SendMessage.
You need to ensure that the SendMessage() method is called with the required parameters.
Which two code segments can you use to achieve this goal? (Each correct answer presents a complete solution. Choose two.)
A. Option A
B. Option B
C. Option C
D. Option D
Answer: C,D
Explanation: D: ExpandoObject Represents an object whose members can be dynamically added and removed at run time. / The ExpandoObject class enables you to add and delete members of its instances at run time and also to set and get values of these members. This class supports dynamic binding, which enables you to use standard syntax like sampleObject.sampleMember instead of more complex syntax like sampleObject.GetAttribute("sampleMember"). / You can pass instances of the ExpandoObject class as parameters. Note that these instances are treated as dynamic objects in C# and late-bound objects in Visual Basic. This means that you do not have IntelliSense for object members and you do not receive compiler errors when you call non-existent members. If you call a member that does not exist, an exception occurs.
Note:
* Visual C# 2010 introduces a new type, dynamic. The type is a static type, but an object of type dynamic bypasses static type checking. In most cases, it functions like it has type object. At compile time, an element that is typed as dynamic is assumed to support any operation. Therefore, you do not have to be concerned about whether the object gets its value from a COM API, from a dynamic language such as IronPython, from the HTML Document Object Model (DOM), from reflection, or from somewhere else in the program. However, if the code is not valid, errors are caught at run time.
Q6. - (Topic 1)
You are developing an application that includes a class named UserTracker. The application includes the following code segment. (Line numbers are included for reference only.)
You need to add a user to the UserTracker instance. What should you do?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: D
Q7. - (Topic 1)
You are developing an application that will process orders. The debug and release versions of the application will display different logo images.
You need to ensure that the correct image path is set based on the build configuration. Which code segment should you use?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: C
Explanation:
There is no such constraint (unless you define one explicitly) RELEASE. http://stackoverflow.com/questions/507704/will-if-release-work-like-if-debug-does-in-c
Q8. DRAG DROP - (Topic 1)
You are developing an application that will include a method named GetData. The GetData() method will retrieve several lines of data from a web service by using a System.IO.StreamReader object.
You have the following requirements:
. The GetData() method must return a string value that contains the entire response from the web service. . The application must remain responsive while the GetData() method runs.
You need to implement the GetData() method.
How should you complete the relevant code? (To answer, drag the appropriate objects to the correct locations in the answer area. Each object may be used once, more than once, or not at all. You may need to drag the split bar between panes or scroll to view content.)
Answer:
Q9. DRAG DROP - (Topic 1)
An application serializes and deserializes XML from streams. The XML streams are in the following format:
The application reads the XML streams by using a DataContractSerializer object that is declared by the following code segment:
var ser = new DataContractSerializer(typeof(Name));
You need to ensure that the application preserves the element ordering as provided in the XML stream.
How should you complete the relevant code? (To answer, drag the appropriate attributes to the correct locations in the answer area-Each attribute may be used once, more than once, or not at all. You may need to drag the split bar between panes or scroll to view content.)
Answer:
Q10. - (Topic 2)
You are implementing a method named ProcessData that performs a long-running task. The ProcessData() method has the following method signature:
public void ProcessData(List<decimal> values, CancellationTokenSource source, CancellationToken token)
If the calling code requests cancellation, the method must perform the following actions:
. Cancel the long-running task.
. Set the task status to TaskStatus.Canceled. You need to ensure that the ProcessData() method performs the required actions.
Which code segment should you use in the method body?
A. if (token.IsCancellationRequested) return;
B. throw new AggregateException();
C. token.ThrowIfCancellationRequested();
D. source.Cancel();
Answer: C
Q11. - (Topic 1)
You are developing an application by using C#. The application includes the following code segment. (Line numbers are included for reference only.)
The DoWork() method must not throw any exceptions when converting the obj object to the IDataContainer interface or when accessing the Data property.
You need to meet the requirements. Which code segment should you insert at line 07?
A. var dataContainer = (IDataContainer)obj;
B. dynamic dataContainer = obj;
C. var dataContainer = obj is IDataContainer;
D. var dataContainer = obj as IDataContainer;
Answer: D
Explanation:
As - The as operator is like a cast operation. However, if the conversion isn't possible, as returns null instead of raising an exception. http://msdn.microsoft.com/en-us/library/cscsdfbt(v=vs.110).aspx
Q12. DRAG DROP - (Topic 1)
You are developing a custom collection named LoanCollection for a class named Loan class.
You need to ensure that you can process each Loan object in the LoanCollection collection by using a foreach loop.
How should you complete the relevant code? (To answer, drag the appropriate code segments to the correct locations in the answer area. Each code segment may be used once, more than once, or not at all. You may need to drag the split bar between panes or scroll to view content.)
Answer:
Q13. - (Topic 2)
You need to write a console application that meets the following requirements:
. If the application is compiled in Debug mode, the console output must display Entering debug mode. . If the application is compiled in Release mode, the console output must display Entering release mode.
Which code should you use?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: D
Explanation: Programmatically detecting Release/Debug mode (.NET)
Boolean isDebugMode = false;
#if DEBUG
isDebugMode = true;
#endif
Reference: http://stackoverflow.com/questions/654450/programmatically-detecting-release-debug-mode-net
Q14. DRAG DROP - (Topic 2)
You are adding a method to an existing application. The method uses an integer named statusCode as an input parameter and returns the status code as a string.
The method must meet the following requirements:
Return "Error" if the statusCode is 0.
Return "Success" if the statusCode is 1.
Return "Unauthorized" if the statusCode is any value other than 0 or l.
You need to implement the method to meet the requirements.
How should you complete the relevant code? (To answer, drag the appropriate statements to the correct locations in the answer area. Each statement may be used once, more than once, or not at all. You may need to drag the split bar between panes or scroll to view content.)
Answer:
Q15. - (Topic 1)
You are developing an application. The application calls a method that returns an array of integers named customerIds. You define an integer variable named customerIdToRemove and assign a value to it. You declare an array named filteredCustomerIds.
You have the following requirements.
Remove duplicate integers from the customerIds array.
Sort the array in order from the highest value to the lowest value.
Remove the integer value stored in the customerIdToRemove variable from the
customerIds array.
You need to create a LINQ query to meet the requirements.
Which code segment should you use?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: C