Microsoft Programming in C# - 070-483 Exam Practice Test
Note: This question is part of a series of questions that present the same scenario. Each question in the series contains a unique solution that might meet the stated goals. Some question sets might have more than one correct solution, while others might not have a correct solution.
After you answer a question in this section, you will NOT be able to return to it. As a result, these questions will not appear in the review screen.
You have the following C# code. (Line numbers are included for reference only.)

You need the foreach loop to display a running total of the array elements, as shown in the following output.
1
3
6
10
15
Solution: You insert the following code at line 02:

Does this meet the goal?
After you answer a question in this section, you will NOT be able to return to it. As a result, these questions will not appear in the review screen.
You have the following C# code. (Line numbers are included for reference only.)

You need the foreach loop to display a running total of the array elements, as shown in the following output.
1
3
6
10
15
Solution: You insert the following code at line 02:

Does this meet the goal?
Correct Answer: A
Vote an answer
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.)

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.)

Correct Answer:

Explanation:
"offset" and "count" parameters of "Stream.Read" / "Stream.Write" methods ALWAYS refer to the array you are sending in the first parameter.
The position of fsSource advances as you read it, unless you seed on it.
You are developing an application that uses multiple asynchronous tasks to optimize performance. The application will be deployed in a distributed environment.
You need to retrieve the result of an asynchronous task that retrieves data from a web service.
The data will later be parsed by a separate task.
Which code segment should you use?

You need to retrieve the result of an asynchronous task that retrieves data from a web service.
The data will later be parsed by a separate task.
Which code segment should you use?

Correct Answer: A
Vote an answer
Explanation: Only visible for Fast2test members. You can sign-up / login (it's free).
An application receives JSON data in the following format:

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

You need to ensure that the ConvertToName() method returns the JSON input string as a Name object.
Which code segment should you insert at line 10?

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

You need to ensure that the ConvertToName() method returns the JSON input string as a Name object.
Which code segment should you insert at line 10?
Correct Answer: D
Vote an answer
Explanation: Only visible for Fast2test members. You can sign-up / login (it's free).
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 first line of the 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.)

You have the following requirements:
* The GetData() method must return a string value that contains the first line of the 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.)

Correct Answer:

Explanation:
Box 1. async Box 2. await Box 3. ReadLineAsync();
Incorrect:
Not Box 3: ReadToEndAsync() is not correct since only the first line of the response is required.
You are developing an application that includes the following code segment:

You need to implement the Open() method of each interface in a derived class named UseResources and call the Open() method of each interface.
Which two code segments should you use? (Each correct answer presents part of the solution. Choose two.)


You need to implement the Open() method of each interface in a derived class named UseResources and call the Open() method of each interface.
Which two code segments should you use? (Each correct answer presents part of the solution. Choose two.)

Correct Answer: B,D
Vote an answer
Explanation: Only visible for Fast2test members. You can sign-up / login (it's free).
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.)


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.)

Correct Answer:

Explanation:
Target 1: The DataContractAttribute.Namespace Property gets or sets the namespace for the data contract for the type. Use this property to specify a particular namespace if your type must return data that complies with a specific data contract.
Target2, target3: We put Order=10 on FirstName to ensure that LastName is ordered first.
Note:
The basic rules for data ordering include:
* If a data contract type is a part of an inheritance hierarchy, data members of its base types are always first in the order.
* Next in order are the current type's data members that do not have the Order property of the DataMemberAttribute attribute set, in alphabetical order.
* Next are any data members that have the Order property of the DataMemberAttribute attribute set. These are ordered by the value of the Order property first and then alphabetically if there is more than one member of a certain Order value. Order values may be skipped.
Reference:
https://msdn.microsoft.com/en-us/library/ms729813(v=vs.110).aspx
https://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractattribute.namespace(v=vs.110).aspx
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?


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?

Correct Answer: C
Vote an answer
Explanation: Only visible for Fast2test members. You can sign-up / login (it's free).
An application will upload data by using HTML form-based encoding. The application uses a method named SendMessage.
The SendMessage() method includes the following code. (Line numbers are included for reference only.)

The receiving URL accepts parameters as form-encoded values.
You need to send the values intA and intB as form-encoded values named a and b, respectively.
Which code segment should you insert at line 04?

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

The receiving URL accepts parameters as form-encoded values.
You need to send the values intA and intB as form-encoded values named a and b, respectively.
Which code segment should you insert at line 04?

Correct Answer: C
Vote an answer
Explanation: Only visible for Fast2test members. You can sign-up / login (it's free).
You have a class named Customer and a class named Order.
The customer class has a property named Orders that contains a list of Order objects.
The Order class has a property named OrderDate that contains the date of the Order.
You need to create a LINQ query that returns all of the customers who had at least one order during the year 2005.
You write the following code.

How should you complete the code? To answer, drag the appropriate code elements to the correct targets in the answer area. Each code element 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.

The customer class has a property named Orders that contains a list of Order objects.
The Order class has a property named OrderDate that contains the date of the Order.
You need to create a LINQ query that returns all of the customers who had at least one order during the year 2005.
You write the following code.

How should you complete the code? To answer, drag the appropriate code elements to the correct targets in the answer area. Each code element 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.

Correct Answer:

You are building a data access layer in an application that contains the following code:

For each of the following statements, select Yes if the statement is true. Otherwise, select No.


For each of the following statements, select Yes if the statement is true. Otherwise, select No.

Correct Answer:

You are developing an application that includes a class named Kiosk. The Kiosk class includes a static property named Catalog. The Kiosk class is defined by the following code segment. (Line numbers are included for reference only.)

You have the following requirements:
* Initialize the _catalog field to a Catalog instance.
* Initialize the _catalog field only once.
* Ensure that the application code acquires a lock only when the _catalog object must be instantiated.
You need to meet the requirements.
Which three code segments should you insert in sequence at line 09? (To answer, move the appropriate code segments from the list of code segments to the answer area and arrange them in the correct order.)


You have the following requirements:
* Initialize the _catalog field to a Catalog instance.
* Initialize the _catalog field only once.
* Ensure that the application code acquires a lock only when the _catalog object must be instantiated.
You need to meet the requirements.
Which three code segments should you insert in sequence at line 09? (To answer, move the appropriate code segments from the list of code segments to the answer area and arrange them in the correct order.)

Correct Answer:

1 - if ( _catalog == null )
2 - lock (_lock)
3 - if ( _catalog == null ) _catalog = new Catalog ( ) ;
Explanation:
After taking a lock you must check once again the _catalog field to be sure that other threads didn't instantiated it in the meantime.
You are developing an application that will convert data into multiple output formats.
The application includes the following code. (Line numbers are included for reference only.)

You are developing a code segment that will produce tab-delimited output. All output routines implement the following interface:

You need to minimize the completion time of the GetOutput() method.
Which code segment should you insert at line 06?

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

You are developing a code segment that will produce tab-delimited output. All output routines implement the following interface:

You need to minimize the completion time of the GetOutput() method.
Which code segment should you insert at line 06?

Correct Answer: A
Vote an answer
Explanation: Only visible for Fast2test members. You can sign-up / login (it's free).


