What should you do 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 13

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


Pete

Pete

The assignment is to create a method. So
“public List GetValidCustomers(){”
should be added before, and
“return validCustomers; }”
should ne added in the end.

Zach

Zach

^^^ what he said

sv1slim

sv1slim

“you need to create a method” so…
1 – public List GetValidCustomers() {
8 – List validCustomers =
5 – (from c in customers where ValidCustomer(c) select c).AsParallel().ToList();
4 – return validCustomers; }

Sbuse

Sbuse

AsParallel shouldn’t be applied on customers?

Najlepszy Programista Swiata DAGO

Najlepszy Programista Swiata DAGO

1,8,7,4

Lord Vader

Lord Vader

1 8 7 4

Lord Vader

Lord Vader

5 vs 7

AsParallel helps us to run queries in parallel, which is enabling parallel threads to improve performance. If you put before WHERE clause the filtering will be done in series, and only then will anything be parallelized.

Tony

Tony

I think 7 make more sense than 5 after read the article. +1 to Lord & ici

AlexP

AlexP

Only 7 the best.
Result #1 (from c in customers where ValidateCustomer(c) select(c)).AsParallel().ToList() = 00:00:25.8819631
Result #2 (from c in customers.AsParallel() where ValidateCustomer(c) select (c)).ToList() = 00:00:06.5830914