コマンドラインでコンパイル


特にアセンブリの参照を追加しなくてもいいようだ。

>type LinqTest.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class LinqTest
{
  public static void Main(string[] args) {
        int[] x = { 0, 1, 2, 3};

        var y =
            from
                p in x
            where
                p % 2 == 0
            select
                p;

        foreach (var p in y)
        {
            Console.WriteLine(p);
        }
  }
}

>set path=%windir%\Microsoft.NET\Framework\v3.5.20404;%PATH%

>csc LinqTest.cs
Microsoft (R) Visual C# Compiler version 9.00.20404
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.

>LinqTest
0
2


ちなみに using System.Linq; がないとwhereの部分で

LinqTest.cs(14,13): error CS1061: 'System.Array' does not contain a definition
        for 'Where' and no extension method 'Where' accepting a first argument
        of type 'System.Array' could be found (are you missing a using directive
        or an assembly reference?)

とかいわれる。