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 6

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


Hans Werner

Hans Werner

The answer misses to return the list of validCustomers (fourth code snippet).

Mike

Mike

The first code snipped should be first in the solution. You need a { for the } in the fourth code snippet too.

rao

rao

See this examples:
https://msdn.microsoft.com/it-it/library/dd460714(v=vs.110).aspx

.AsParralel() must follow the collection in from clause.

So, for me, the correct answer would be:

public List GetValidCustomers()
{
List validCustomers =
(from ci in customers.AsParallel()….)
return validCustomers
}

TheCoder

TheCoder

Agreed, you want the AsParallel as early as possible making sense. It will then run all customers as parallel and each task will wait for the slow ValidateCustomer method.

Zag

Zag

Yes.

If it was added at last, anyway what’s the point.