70-483 Exam - Programming in C#

certleader.com

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

Q2. - (Topic 2) 

You need to write a method that retrieves data from a Microsoft Access 2013 database. 

The method must meet the following requirements: 

Be read-only. 

Be able to use the data before the entire data set is retrieved. 

Minimize the amount of system overhead and the amount of memory usage. 

Which type of object should you use in the method? 

A. SqlDataAdapter 

B. DataContext 

C. DbDataAdapter 

D. OleDbDataReader 

Answer:

Explanation: OleDbDataReader Class 

Provides a way of reading a forward-only stream of data rows from a data source. 

Example: 

OleDbConnection cn = new OleDbConnection(); 

OleDbCommand cmd = new OleDbCommand(); 

DataTable schemaTable; 

OleDbDataReader myReader; 

//Open a connection to the SQL Server Northwind database. 

cn.ConnectionString = "Provider=SQLOLEDB;Data Source=server;User ID=login; 

Password=password;Initial Catalog=Northwind"; 

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

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

Explanation: #elif lets you create a compound conditional directive. The #elif expression will be evaluated if neither the preceding #if (C# Reference) nor any preceding, optional, #elif directive expressions evaluate to true. If a #elif expression evaluates to true, the compiler evaluates all the code between the #elif and the next conditional directive. For example: #define VC7 //... #if debug Console.Writeline("Debug build"); #elif VC7 Console.Writeline("Visual Studio 7"); #endif 

Incorrect: Not B: 

* System.Reflection.Assembly.GetExecutingAssembly Method Gets the assembly that contains the code that is currently executing.* Assembly.IsDefined Method Indicates whether or not a specified attribute has been applied to the assembly. 

* System.Dignostics.Debugger Class Enables communication with a debugger. 

Property: IsAttached 

Gets a value that indicates whether a debugger is attached to the process. 

Q5. - (Topic 1) 

You are developing an application. The application converts a Location object to a string by using a method named WriteObject. 

The WriteObject() method accepts two parameters, a Location object and an XmlObjectSerializer object. 

The application includes the following code. (Line numbers are included for reference only.) 

You need to serialize the Location object as XML. 

Which code segment should you insert at line 20? 

A. new XmlSerializer(typeof(Location)) 

B. new NetDataContractSerializer() 

C. new DataContractJsonSerializer(typeof (Location)) 

D. new DataContractSerializer(typeof(Location)) 

Answer:

Explanation: 

The code is using [DataContract] attribute here so need to used DataContractSerializer class. 

Q6. - (Topic 2) 

You are developing an application. 

You need to declare a delegate for a method that accepts an integer as a parameter, and then returns an integer. 

Which type of delegate should you use? 

A. Action<int> 

B. Action<int, int> 

C. Func<int, int> 

D. Func<int> 

Answer:

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

Explanation: The MatchCollection.GetEnumerator method returns an enumerator that 

iterates through a collection. 

Note: 

The MatchCollection Class represents the set of successful matches found by iteratively 

applying a regular expression pattern to the input string. 

Reference: MatchCollection.GetEnumerator Method 

https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.matchcollection.getenumerator(v=vs.110).aspx 

Q8. - (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. 

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

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 

Q10. - (Topic 1) 

You are developing an application that uses structured exception handling. The application includes a class named Logger. The Logger class implements a method named Log by using the following code segment: 

public static void Log(Exception ex) { } 

You have the following requirements: 

. Log all exceptions by using the Log() method of the Logger class. 

. Rethrow the original exception, including the entire exception stack. 

You need to meet the requirements. Which code segment should you use? 

A. Option A 

B. Option B 

C. Option C 

D. Option D 

Answer: