Skip to main content
C# / .NET Output Prediction Medium +20 XP

LINQ Count

What does this return?

C# / .NETRead-only
var nums = new[] {1,2,3,4,5};
var result = nums.Where(n => n > 2).Count();

What is the output?

Show answer and explanation

Answer: 3

Where(n => n > 2) filters to [3,4,5]. Count() returns 3.

Hint: Count elements greater than 2.

What this challenge tests

Output Prediction in C# / .NET: linq, collections.

Related challenges