LINQ パズル
http://www.infoq.com/news/2007/11/Functional-CSharp
int[] b = Enumerable.Range( 1, 20 ).ToArray();
Correct?
using System; using System.Linq; class P { static void Main() { int[] a = new int[ 20 ]; for ( int x = 0; x < a.Length; x++ ) a[ x ] = x + 1; int[] b = Enumerable.Range( 1, 20 ).ToArray(); Console.WriteLine( a.SequenceEqual( b ) ); Console.ReadKey(); } }
おまけ
int[] c = new int[ 20 ]; for ( int x = 0; x < c.Length; x++ ) c[ x ] = x * 2; int[] d = Enumerable.Range( 0, 20 ).Select( n => n * 2 ).ToArray(); Console.WriteLine( c.SequenceEqual( d ) );