Q81. - (Topic 2) 

You are implementing a new method named ProcessData. The ProcessData() method calls a third-party component that performs a long-running operation to retrieve stock information from a web service. 

The third-party component uses the IAsyncResult pattern to signal completion of the long-running operation so that the UI can be updated with the new values. 

You need to ensure that the calling code handles the long-running operation as a System.Threading.Tasks.Task object to avoid blocking the UI thread. 

Which two actions should you perform? (Each correct answer presents part of the solution. Choose two.) 

A. Create a TaskCompletionSource<T> object. 

B. Call the component by using the TaskFactory.FromAsync() method. 

C. Apply the following attribute to the ProcessData() method signature: [Methodlmpl(MethodlmplOptions.Synchronized)] 

D. Apply the async modifier to the ProcessData() method signature. 

Answer: A,B 

Explanation: A: In many scenarios, it is useful to enable a Task<TResult> to represent an external asynchronous operation. TaskCompletionSource<TResult> is provided for this purpose. It enables the creation of a task that can be handed out to consumers, and those consumers can use the members of the task as they would any other. However, unlike most tasks, the state of a task created by a TaskCompletionSource is controlled explicitly by the methods on TaskCompletionSource. This enables the completion of the external asynchronous operation to be propagated to the underlying Task. The separation also ensures that consumers are not able to transition the state without access to the corresponding TaskCompletionSource. 

B: TaskFactory.FromAsync Method 

Creates a Task that represents a pair of begin and end methods that conform to the 

Asynchronous Programming Model pattern. Overloaded. 

Example: 

TaskFactory.FromAsync Method (IAsyncResult, Action<IAsyncResult>) 

Creates a Task that executes an end method action when a specified IAsyncResult completes. 

Note: 

* System.Threading.Tasks.Task Represents an asynchronous operation. 


Q82. - (Topic 2) 

You are developing an application by using C#. The application will write events to an event log. You plan to deploy the application to a server. 

You create an event source named AppSource and a custom log named AppLog on the server. 

You need to write events to the custom log. Which code segment should you use? 

A. Option A 

B. Option B 

C. Option C 

D. Option D 

Answer:

Explanation: Source should be AppSource: 

* New-EventLog 

Creates a new event log and a new event source on a local or remote computer. 

Parameters include: 

-Source<String[]> 

Specifies the names of the event log sources, such as application programs that write to the event log. This parameter is required. 


Q83. - (Topic 2) 

You are developing a class named Scorecard. The following code implements the Scorecard class. (Line numbers are included for reference only.) 

You create the following unit test method to test the Scorecard class implementation: 

You need to ensure that the unit test will pass. What should you do? 

A. Option A 

B. Option B 

C. Option C 

D. Option D 

Answer:


Q84. - (Topic 1) 

You are developing an application. The application includes classes named Mammal and Animal and an interface named IAnimal. 

The Mammal class must meet the following requirements: . It must either inherit from the Animal class or implement the IAnimal interface. . It must be inheritable by other classes in the application. You need to ensure that the Mammal class meets the requirements. 

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: A,C 

Explanation: 

When applied to a class, the sealed modifier prevents other classes from inheriting from it. http://msdn.microsoft.com/en-us/library/88c54tsw(v=vs.110).aspx 


Q85. - (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:


Q86. - (Topic 1) 

You are developing an application that includes the following code segment. (Line numbers are included for reference only.) 

You need to ensure that the application accepts only integer input and prompts the user each time non-integer input is entered. 

Which code segment should you add at line 19? 

A. If (!int.TryParse(sLine, out number)) 

B. If ((number = Int32.Parse(sLine)) == Single.NaN) 

C. If ((number = int.Parse(sLine)) > Int32.MaxValue) 

D. If (Int32.TryParse(sLine, out number)) 

Answer:

Explanation: 

B and C will throw exception when user enters non-integer value. D is exactly the opposite what we want to achieve. 

Int32.TryParse - Converts the string representation of a number to its 32-bit signed integer equivalent. A return value indicates whether the conversion succeeded. http://msdn.microsoft.com/en-us/library/f02979c7.aspx 


Q87. - (Topic 1) 

You are creating a console application by using C#. 

You need to access the assembly found in the file named car.dll. 

Which code segment should you use? 

A. Assembly.Load(); 

B. Assembly.GetExecutingAssembly(); 

C. This.GetType(); 

D. Assembly.LoadFile("car.dll"); 

Answer:

Explanation: 

Assembly.LoadFile - Loads the contents of an assembly file on the specified path. http://msdn.microsoft.com/en-us/library/b61s44e8.aspx 


Q88. - (Topic 2) 

You are developing a method named GetHash that will return a hash value for a file. The method includes the following code. (Line numbers are included for reference only.) 

You need to return the cryptographic hash of the bytes contained in the fileBytes variable. Which code segment should you insert at line 05? 

A. Option A 

B. Option B 

C. Option C 

D. Option D 

Answer:


Q89. - (Topic 1) 

You are developing an application. The application includes classes named Employee and Person and an interface named IPerson. 

The Employee class must meet the following requirements: 

. It must either inherit from the Person class or implement the IPerson interface. . It must be inheritable by other classes in the application. 

You need to ensure that the Employee class meets the requirements. 

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: B,D 

Explanation: 

Sealed - When applied to a class, the sealed modifier prevents other classes from inheriting from it. http://msdn.microsoft.com/en-us/library/88c54tsw(v=vs.110).aspx 


Q90. - (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:

Explanation: 

The GetData() method should be private. It would then only be visible within the Person class.