Question 6 of 268

DRAG DROP -

You are developing an application by using C#. The application includes an array of decimal values named loanAmounts. You are developing a LINQ query to return the values from the array.

The query must return decimal values that are evenly divisible by two. The values must be sorted from the lowest value to the highest value.

You need to ensure that the query correctly returns the decimal values.

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

Select and Place:

    Correct Answer:

    Note: In a query expression, the orderby clause causes the returned sequence or subsequence (group) to be sorted in either ascending or descending order.

    Examples:

    // Query for ascending sort.

    IEnumerable sortAscendingQuery =

    from fruit in fruits

    orderby fruit //"ascending" is default

    select fruit;

    // Query for descending sort.

    IEnumerable sortDescendingQuery =

    from w in fruits

    orderby w descending

    select w;

Question 7 of 268

You are developing an application. The application includes a method named ReadFile that reads data from a file.

The ReadFile() method must meet the following requirements:

✑ It must not make changes to the data file.

✑ It must allow other processes to access the data file.

✑ It must not throw an exception if the application attempts to open a data file that does not exist.

You need to implement the ReadFile() method.

Which code segment should you use?

    Correct Answer: A

    File.Open with FileMode.OpenOrCreate ensures that if the file does not exist, it will be created, thus preventing an exception. FileAccess.Read ensures that the data file is only read and not altered. FileShare.ReadWrite allows other processes to access the file for both reading and writing. Therefore, this code segment meets the requirements of not altering the file, allowing other processes to access it, and not throwing an exception if the file does not exist.

Question 8 of 268

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?

    Correct Answer: C

    To convert a JSON string to an object of a specified type, you can use the Deserialize<T> method provided by JavaScriptSerializer. This method efficiently maps the JSON data to the specified class type. In the given context, the method Deserialize<Name> perfectly fits to parse the JSON string into an instance of the Name class, ensuring all properties like FirstName, LastName, and Values are correctly populated.

Question 9 of 268

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 a JSON object.

Which code segment should you insert at line 20?

    Correct Answer: D

    To serialize a Location object as a JSON object, you should use the DataContractJsonSerializer class. The DataContractJsonSerializer class is designed for handling JSON data, while other serializers like DataContractSerializer or XmlSerializer are intended for XML. Since the requirement is to serialize the object as JSON, DataContractJsonSerializer is the appropriate choice.

Question 10 of 268

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?

    Correct Answer: D

    To avoid exceptions when converting the obj object to the IDataContainer interface or when accessing the Data property, you should use the 'as' operator. The 'as' operator attempts to cast an object to a specific type and returns null if the cast fails, rather than throwing an exception. This ensures that the DoWork() method will proceed without errors even if the conversion is not possible. Hence, the code segment that should be inserted at line 07 is 'var dataContainer = obj as IDataContainer;'