Skip to content

Instantly share code, notes, and snippets.

@baba-s
Last active August 29, 2015 13:58
Show Gist options
  • Select an option

  • Save baba-s/9947109 to your computer and use it in GitHub Desktop.

Select an option

Save baba-s/9947109 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
/// <summary>
/// Enumerable 型に関する汎用メソッドを管理するクラス
/// </summary>
public static partial class EnumerableCommon
{
/// <summary>
/// 指定した範囲内の整数のシーケンスを生成して新しいフォームに射影します
/// </summary>
/// <typeparam name="TResult">selector によって返される値の型</typeparam>
/// <param name="start">シーケンス内の最初の整数の値</param>
/// <param name="count">生成する連続した整数の数</param>
/// <param name="selector">各要素に適用する変換関数</param>
/// <returns>各要素に対して変換関数を呼び出した結果として得られる要素を含む IEnumerable のインスタンス</returns>
public static IEnumerable<TResult> RangeSelect<TResult>(int start, int count, Func<int, TResult> selector)
{
return Enumerable.Range(start, count).Select(selector);
}
/// <summary>
/// 指定した範囲内の整数のシーケンスを生成して新しいフォームに射影します
/// </summary>
/// <typeparam name="TResult">selector によって返される値の型</typeparam>
/// <param name="count">生成する連続した整数の数</param>
/// <param name="selector">各要素に適用する変換関数</param>
/// <returns>各要素に対して変換関数を呼び出した結果として得られる要素を含む IEnumerable のインスタンス</returns>
public static IEnumerable<TResult> RangeSelect<TResult>(int count, Func<int, TResult> selector)
{
return RangeSelect(0, count, selector);
}
/// <summary>
/// 指定した範囲内の整数のシーケンスを生成します
/// </summary>
/// <param name="count">生成する連続した整数の数</param>
/// <returns>連続した整数の範囲を含む IEnumerable</returns>
public static IEnumerable<int> Range(int count)
{
return Enumerable.Range(0, count);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment