タグ

rangeとcsに関するkiyo_hikoのブックマーク (2)

  • Enumerable.Range(Int32, Int32) メソッド (System.Linq)

    例 次のコード例では、 を使用 Range して値のシーケンスを生成する方法を示します。 // Generate a sequence of integers from 1 to 10 // and then select their squares. IEnumerable<int> squares = Enumerable.Range(1, 10).Select(x => x * x); foreach (int num in squares) { Console.WriteLine(num); } /* This code produces the following output: 1 4 9 16 25 36 49 64 81 100 */ ' Generate a sequence of integers from 1 to 10 ' and project their squ

    Enumerable.Range(Int32, Int32) メソッド (System.Linq)
    kiyo_hiko
    kiyo_hiko 2015/07/28
    SchemeのiotaとかHaskellの1..nのようなもの // Enumerable.Range(1,100).Select(n => new {index = n, display = new Func<int, string>(i => Convert.ToString(i * i))(n)}).Dump(); こんな感じでクエリーの種にできう。あと即時関数はFunc<a, b> (a → bの意)でよさげだ
  • How get list of datetimes from date range?

    kiyo_hiko
    kiyo_hiko 2015/07/22
    BAを関数化した → public List<DateTime> Term(DateTime from, DateTime to){TimeSpan ts = to - from;var days = new List<DateTime>();for (int i = 0; i <= ts.Days; i++){days.Add(from.AddDays(i));}return days;} // ところでLispのloopかiota+mapcarみたく一発で書ける方法ないかな
  • 1