LoginSignup
9
7

More than 5 years have passed since last update.

LINQやRxのAggregateの初期値

Posted at

Aggregateの第一引数に初期値を渡すことができるのは知ってたんですが、
listなどのインスタンスを置いたりすることも可能なんですね、知らなかった。

LINQのAggregate.cs
var result = Enumerable.Range(1, 10).Aggregate(new List<int>(), (list, x) => {
  list.Add(x);
  return list;
});
result.ForEach(x => Console.WriteLine(x));

上記はLINQですが、RxのAggregateも同様に使用できるみたいです。

Aggregate<TSource, TAccumulate>(TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> func)
だそうです。

9
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
7