PrepAway - Latest Free Exam Questions & Answers

You need to create a method that returns a list of vali…

DRAG DROP
You have a method named GetCustomerIDs that returns a list of integers. Each entry in the list represents a
customer ID that is retrieved from a list named Customers. The Customers list contains 1,000 rows.
Another developer creates a method named ValidateCustomer that accepts an integer parameter and returns a
Boolean value. ValidateCustomer returns true if the integer provided references a valid customer.
ValidateCustomer can take up to one second to run.
You need to create a method that returns a list of valid customer IDs. The code must execute in the shortest
amount of time.
What should you do? (Develop the solution by selecting and ordering the required code snippets. You may not
need all of the code snippets.)
Select and Place:

PrepAway - Latest Free Exam Questions & Answers

Answer:

Explanation:
Note:
* ParallelEnumerable.AsParallel Method
Enables parallelization of a query.
/ We parallelize the exution of the ValidateCustomer instances.

7 Comments on “You need to create a method that returns a list of vali…

  1. Mo says:

    1 – public List GetValidCustomers() {
    8 – List validCustomers =
    7 – (from c in customers where ValidCustomer(c) select c).AsParallel().ToList();
    4 – return validCustomers; }




    4



    9
      1. Rob says:

        Mo’s answer is correct if you look at the numbers only. Number 7 has the wrong code, needs to be

        (from c in customers.AsParallel() where ValidCustomer(c) select c).ToList();




        16



        2
  2. Paul says:

    The “AsParallel()” should be before the where-clause:
    public List GetValidCustomers()
    {
    List validCustomer =
    (from c in customers.AsParallel()
    where ValidateCustomer(c)
    select c).ToList();
    return validCustomers;
    }




    17



    2
    1. Dai Nguyen says:

      INCORREECT, customers.AsParallel()… will run longer time than (from c in customers where ValidCustomer(c) select c).AsParallel()… The expected of this question is run in shortest time.




      4



      1

Leave a Reply