PrepAway - Latest Free Exam Questions & Answers

Which code segment should you use?

You are implementing an ASP.NET application. You add the following code segment.

You need to add code to return a list of all Person objects except those with a UserId that is
contained in the secretUsers list. The resulting list must not contain duplicates. Which code segment
should you use?

PrepAway - Latest Free Exam Questions & Answers

A.
var secretPeople = (from p in allPeople
from u in secretUsers
where p.UserId == u
select p).Distinct();
return allPeople.Except(secretPeople);

B.
return from p in allPeople
from u in secretUsers
where p.UserId != u
select p;

C.
return (from p in allPeople
from u in secretUsers
where p.UserId != u
select p).Distinct();

D.
List<Person> people = new List<Person>(
from p in allPeople
from u in secretUsers
where p.UserId != u
select p);
return people.Distinct();


Leave a Reply