Bird
0
0

Given the class Person { public string Name; public int Age; } and a list people containing: John(20), Lisa(40), and Mark(35), what will this LINQ query return?

medium📝 Predict Output Q4 of 15
C Sharp (C#) - LINQ Fundamentals
Given the class Person { public string Name; public int Age; } and a list people containing: John(20), Lisa(40), and Mark(35), what will this LINQ query return?
var result = people.Where(p => p.Age < 30).Select(p => p.Name);
AA list containing "John"
BA list containing "Lisa" and "Mark"
CA list containing "John" and "Mark"
DAn empty list
Step-by-Step Solution
Solution:
  1. Step 1: Understand the Where clause

    The condition is p.Age < 30, so only persons younger than 30 are selected.
  2. Step 2: Identify matching persons

    John is 20 (matches), Lisa is 40 (does not match), Mark is 35 (does not match).
  3. Step 3: Select names

    Only John's name is selected.
  4. Final Answer:

    A list containing "John" -> Option A
  5. Quick Check:

    Check ages against condition < 30 [OK]
Quick Trick: Filter first, then select properties [OK]
Common Mistakes:
MISTAKES
  • Including persons who do not meet the age condition
  • Confusing < with > in the condition
  • Selecting the whole object instead of just the name

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Sharp (C#) Quizzes