2014年7月2日水曜日

開発環境

Head First C#―頭とからだで覚えるC#の基本 (Andrew Stellman (著)、Jennifer Green (著)、佐藤 嘉一 (監修)、木下 哲也 (翻訳)、オライリージャパン)の11章(LINQ: データの管理)、LINQマグネット(p.481)を解いてみる。

LINQマグネット(p.481)

コード

Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] badgers = { 36, 5, 91, 3, 41, 69, 8 };
            var skunks = from pigeon in badgers
                         where (pigeon != 36 && pigeon < 50)
                         orderby pigeon descending
                         select pigeon + 5;
            var bears = skunks.Take(3);
            var weasels = from sparrow in bears
                          select sparrow - 1;
            
            Console.WriteLine("Get your kicks on route {0}", weasels.Sum());
        }
    }
}

出力結果(コマンドプロンプト)

Get your kicks on route 66
続行するには何かキーを押してください . . .

0 コメント:

コメントを投稿