プログラミング言語 開発スレ( ´�D`)
■ このスレッドは過去ログ倉庫に格納されています
0425デフォルトの名無しさん
NGNG単純な列挙にはC#のforeachに近い構文を使用してはどうでしょう。
using System;
using System.Collections;
class Range : IEnumerable
{
public Range( int first, int last ){ First = first; Last = last; }
public IEnumerator GetEnumerator() { return new Enumerator( First, Last ); }
public readonly int First, Last;
class Enumerator : IEnumerator
{
public Enumerator( int first, int last ) { First = first; Last = last; current = first-1; }
public bool MoveNext(){ return (++current<Last); }
public void Reset() { current = First-1; }
public object Current { get { return current; } }
public readonly int First, Last;
int current;
}
}
class Foo
{
static int Main()
{
foreach( int i in new Range( 10, 20 ) )
{
Console.WriteLine( i );
}
return 0;
}
}
■ このスレッドは過去ログ倉庫に格納されています