You need to create a method that returns a list of valid customer IDs

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

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

Answer: See the explanation.

Explanation:
Box 1:

Box 2:

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



Leave a Reply 10

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


My'nD

My'nD

Must add “puclic List GetValidCustomers() {” first and “return validCustomers }” last to be fully correct

lucky

lucky

how can we will build these codes?can you write me?

Deav

Deav

1, 8, 7, 4 is the correct order.

ManojP

ManojP

correct answer is 1, 8, 7, 4
as AsParallel() should be after source not at last…
so instead of 5 it should be 7

Raghu

Raghu

correct answer is 1,8,7,4

tommy

tommy

Shoud be 1874, I did this test

var list = new List<Func>{
() => “thred1: ” + Thread.CurrentThread.ManagedThreadId,
() => “thred2: ” + Thread.CurrentThread.ManagedThreadId,
() => “thred3: ” + Thread.CurrentThread.ManagedThreadId,
() => “thred4: ” + Thread.CurrentThread.ManagedThreadId,
};

var a = (from c in list.AsParallel()
select c()).ToList();
var b = (from c in list
select c()).AsParallel().ToList();