LINQ and lambdas - Get control of your data - query(from, in ,where, orderby, select, descending), var keyword
Head First C Sharp: A Learner’s Guide to Real-World Programming with C Sharp and .NET (Andrew Stellman(著)、Jennifer Greene(著)、O’Reilly Media)の Chapter 9(LINQ and lambdas - Get control of your data)、p.481(LINQ magnets)の解答を求めてみる。
コード
Program.cs
int[] badgers = { 36, 5, 91, 3, 41, 69, 8 };
var skunk = from pigeon in badgers
where pigeon != 36 && pigeon < 50
orderby pigeon descending
select pigeon + 5;
var bears = skunk.Take(3);
var weasels = from sparrow in bears
select sparrow - 1;
Console.WriteLine("Get your kicks on route {0}", weasels.Sum());
入出力結果(Terminal, Zsh)
% dotnet run
Get your kicks on route 66
%