70-483 Exam - Programming in C#

certleader.com

Q1. - (Topic 2) 

You are developing an application that includes a class named Employee and a generic list 

of employees. The following code segment declares the list of employees: 

List<Employee> employeesList = new List<Employee>(); 

You populate the employeesList object with several hundred Employee objects. 

The application must display the data for five Employee objects at a time. 

You need to create a method that will return the correct number of Employee objects. 

Which code segment should you use? 

A. Option A 

B. Option B 

C. Option C 

D. Option D 

Answer:

Q2. DRAG DROP - (Topic 2) 

You are creating a method that will split a single input file into two smaller output files. 

The method must perform the following actions: 

. Create a file named header.dat that contains the first 20 bytes of the input file. 

. Create a file named body.dat that contains the remainder of the input file. 

You need to create the method. 

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:  

Q3. - (Topic 2) 

You are developing an application. 

The application contains the following code: 

When you compile the code, you receive the following syntax error message: "A previous catch clause already catches all exceptions of this or a super type ('System.Exception')." 

You need to ensure that the code can be compiled. What should you do? 

A. Catch the ArgumentException exception instead of the ArgumentNullException exception. 

B. Throw a new exception in the second catch block. 

C. Catch the ArgumentNullException exception first. 

D. Re-throw the exception caught by the second catch block. 

Answer:

Q4. - (Topic 2) 

You are implementing a new method named ProcessData. The ProcessData() method calls a third-party component that performs a long-running operation. 

The third-party component uses the IAsyncResult pattern to signal completion of the long-running operation. 

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

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

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

B. Create a TaskCompletionSource<T> object. 

C. Apply the async modifier to the method signature. 

D. Apply the following attribute to the method signature: [MethodImpl(MethodImplOptions.Synchronized)] 

Answer: A,B 

Explanation: A: 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. 

B: 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. 

Note: 

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

Q5. - (Topic 1) 

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:

Explanation: Use the == operator to compare values and in this case also use the null literal. 

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:

Explanation: * XmlWriterTraceListener 

Directs tracing or debugging output as XML-encoded data to a TextWriter or to a Stream, 

such as a FileStream. 

Q7. 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:  

Q8. - (Topic 1) 

You are implementing a method named Calculate that performs conversions between value types and reference types. The following code segment implements the method. (Line numbers are included for reference only.) 

You need to ensure that the application does not throw exceptions on invalid conversions. 

Which code segment should you insert at line 04? 

A. int balance = (int) (float)amountRef; 

B. int balance = (int)amountRef; 

C. int balance = amountRef; 

D. int balance = (int) (double) amountRef; 

Answer:

Q9. - (Topic 1) 

You are developing an application that uses the Microsoft ADO.NET Entity Framework to retrieve order information from a Microsoft SQL Server database. The application includes the following code. (Line numbers are included for reference only.) 

The application must meet the following requirements: 

. Return only orders that have an OrderDate value other than null. 

. Return only orders that were placed in the year specified in the OrderDate property or in a later year. 

You need to ensure that the application meets the requirements. 

Which code segment should you insert at line 08? 

A. Where order.OrderDate.Value != null && order.OrderDate.Value.Year > = year 

B. Where order.OrderDate.Value = = null && order.OrderDate.Value.Year = = year 

C. Where order.OrderDate.HasValue && order.OrderDate.Value.Year = = year 

D. Where order.OrderDate.Value.Year = = year 

Answer:

Explanation: *For the requirement to use an OrderDate value other than null use: OrderDate.Value != null 

*For the requirement to use an OrderDate value for this year or a later year use: OrderDate.Value>= year 

Q10. - (Topic 2) 

You are implementing a method named GetValidEmailAddresses. The GetValidEmailAddresses() method processes a list of string values that represent email addresses. 

The GetValidEmailAddresses() method must return only email addresses that are in a valid format. 

You need to implement the GetValidEmailAddresses() method. 

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: Note: 

* List<T>.Add Method 

Adds an object to the end of the List<T>.