Which code segment should you use?

You are developing an application. The application calls a method that returns an array of integers named
employeeIds. You define an integer variable named employeeIdToRemove and assign a value to it. You
declare an array named filteredEmployeeIds. You have the following requirements:
Remove duplicate integers from the employeeIds array.
Sort the array in order from the highest value to the lowest value.
Remove the integer value stored in the employeeIdToRemove variable from the employeeIds array.
You need to create a LINQ query to meet the requirements. Which code segment should you use?

You are developing an application. The application calls a method that returns an array of integers named
employeeIds. You define an integer variable named employeeIdToRemove and assign a value to it. You
declare an array named filteredEmployeeIds. You have the following requirements:
Remove duplicate integers from the employeeIds array.
Sort the array in order from the highest value to the lowest value.
Remove the integer value stored in the employeeIdToRemove variable from the employeeIds array.
You need to create a LINQ query to meet the requirements. Which code segment should you use?

A.
int[] filteredEmployeeIds = employeeIds.Where(value => value !=
employeeIdToRemove).OrderBy(x => x).ToArray();

B.
int[] filteredEmployeeIds = employeeIds.Where(value => value !=
employeeIdToRemove).OrderByDescending(x => x).ToArray();

C.
int[] filteredEmployeeIds = employeeIds.Distinct().Where(value => value !=
employeeIdToRemove).OrderByDescending(x => x).ToArray();

D.
int[] filteredEmployeeIds = employeeIds.Distinct().OrderByDescending(x =>
x).ToArray();

Explanation:
C is the only one of the answers that includes the “Distinct” clause in order to eliminate duplicate values.



Leave a Reply 0

Your email address will not be published. Required fields are marked *