SubRange Enumerator

ちょっとだけ実用的な列挙子。また列挙かよってつっこみはなしの方向でw
指定範囲だけ列挙してくれる SubRange Enumerator。for 文使えよってつっこみもなしの方向でw

using System;
using System.Collections.Generic;

namespace SubRangeEnumerator
{
	public class SubRangeList<T> : List<T>
	{
		public IEnumerable<T> SubRange( int index, int count )
		{
			if ( ( index < 0 ) || ( count < 0 ) )
			{
				throw new ArgumentOutOfRangeException();
			}

			if ( this.Count < ( index + count ) )
			{
				throw new ArgumentException();
			}

			for ( int i = index; i < ( index + count ); i++ )
			{
				yield return this[ i ];
			}
		}
	}

	public class Program
	{
		private const int Max = 5;

		static void Main()
		{
			SubRangeList<int> list = new SubRangeList<int>();
			for ( int i = 0; i < Max; i++ )
			{
				list.Add( i );
			}

			foreach ( int x in list.SubRange( 1, 3 ) )
			{
				Console.WriteLine( x );
			}

			Console.ReadLine();
		}
	}
}