How does the .Max(...) work in LINQ? What will be the result of the following code?
var result = new[] { "hello", "world", "factory", "x" }.Max(p => p.Length);
Experience Level:
Junior
Tags:
.NET
C#
LINQ
Answer
Explanation
The transform function p => p.Length will be executed on evey element of the array and the Length of the element will be identified. The biggest length will then be returned.
The value of the variable result will be 7.
Related C# job interview questions
-
Could you explain on the following example what a deferred execution is and what materialization is? What will the output be?
.NET C# LINQ Performance Mid-level -
What array initialization syntaxes do you know?
.NET C# Mid-level -
What is a difference between partial class and partial method and what are they good for?
.NET C# Senior