Which expression should you use?

The application must provide a component part list for any product. The component part list must give the quantity of
each distinct part that is required to manufacture that product.

You need to create a LINQ expression that delivers a a result of type IEnumerable<Tuple<int,Part>> to meet the requirements.
Which expression should you use?

The application must provide a component part list for any product. The component part list must give the quantity of
each distinct part that is required to manufacture that product.

You need to create a LINQ expression that delivers a a result of type IEnumerable<Tuple<int,Part>> to meet the requirements.
Which expression should you use?

A.
IEnumerable<Tuple<int, Part>> result = part.Children
.Distinct()
.GroupBy(p => p)
.Select(g => Tuple.Create(g.Count(), g.Key));

B.
IEnumerable<Tuple<int, Part>> result = part.Descendants
.GroupBy(p => p)
.Select(g => Tuple.Create(g.Count(), g.Key));

C.
IEnumerable<Tuple<int, Part>> result = part.Descendants
.ToDictionary(c => c)
.Select(d => Tuple.Create(d.Value.Children.Count(), d.Key));

D.
IEnumerable<Tuple<int, Part>> result = part.Children
.GroupBy(p => p)
.Select(g => Tuple.Create(g.Count(), g.Key));

E.
IEnumerable<Tuple<int, Part>> result = part.Descendants
.Distinct()
.GroupBy(p => p)
.Select(g => Tuple.Create(g.Count(), g.Key));



Leave a Reply 6

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


Artem

Artem

sorry, i mean between B and D

Jim BBQ

Jim BBQ

This one is part of a case study, that information is given there.

Michael

Michael

Why doesn’t suggested answer use Distinct() method? Like E?

John Galt

John Galt

Because Distinct would remove duplicate parts, and the question asks you to get their totals.