//------------------------------------------------------------------------------------------------
OrderBy
SyntaxEditor Code Snippet
public static IEnumerable<Point> OrderPoints(IEnumerable<Point> points)
{
return from point in points
orderby point.X,point.Y
select point;
}
//-----------------------------------------------------------------------------------------------
let
SyntaxEditor Code Snippet
return from house in houses
let addressSplitByCommas = house.Address.Split(',')
select addressSplitByCommas.Count()==3 ?
addressSplitByCommas[1].TrimStart(' '):
house.Address;
example input
new House("Maple Town, 123 Old Road, South Slope Borough")
result
"123 Old Road"
//------------------------------
SyntaxEditor Code Snippet
return (from student in students
let maxMark = student.Marks.Any()?
student.Marks.Max():0
orderby maxMark descending
select $"{student.Name}: {maxMark}")
.FirstOrDefault();
//-----------------------------------------------------------------------------------------------
SelectMany
SyntaxEditor Code Snippet
return from number in numbers.Order()
let divisors = (from potentialDivisor in Enumerable.Range(1, number)
where number % potentialDivisor == 0
select potentialDivisor).ToList()
from divisor in divisors.Order()
select $"Number {number} is " + $"divisible by {divisor}";
example input
{1,4}
result
Number 1 is divisible by 1
Number 4 is divisible by 1
Number 4 is divisible by 2
Number 4 is divisible by 4