本文整理汇总了C#中Subject.Scan方法的典型用法代码示例。如果您正苦于以下问题:C# Subject.Scan方法的具体用法?C# Subject.Scan怎么用?C# Subject.Scan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Subject
的用法示例。
在下文中一共展示了Subject.Scan方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Observe
private void Observe(object sender, EventArgs e)
{
//var source = Observable.Range(1,100);
var source = new Subject<int>();
source.Scan(Agg).Subscribe(number => Messages.Items.Add(number),
ex => Messages.Items.Add("OnError: " + ex.Message),
() => Messages.Items.Add("OnCompleted"));
for (int i = 1; i < 101; i++)
{
source.OnNext(i);
}
}
示例2: Run
public static void Run()
{
{
// IObservable<TSource> Aggregate<TSource>(
// this IObservable<TSource> source,
// Func<TSource, TSource, TSource> accumulator)
var numbers = Observable.Range(0, 10);
var sum = numbers.Aggregate(0, (acc, currentValue) => acc + currentValue);
sum.Dump("sum");
// problem
// 1. must be same type, 2. need at least one value
}
{
// IObservable<TAccumulate> Aggregate<TSource, TAccumulate>(
// this IObservable<TSource> source,
// TAccumulate seed,
// Func<TAccumulate, TSource, TAccumulate> accumulator)
var chars = new Char[] { 'a', 'b', 'c' }.ToObservable();
var count = chars.Aggregate(0, (acc, _) => acc + 1);
count.Dump("count");
}
{
//
var numbers = new Subject<int>();
var scan = numbers.Scan(0, (acc, current) => acc + current);
numbers.Dump("numbers");
scan.Dump("scan");
numbers.OnNext(1);
numbers.OnNext(2);
numbers.OnNext(3);
numbers.OnCompleted();
// source.Aggregate(0, (acc, current) => acc + current);
// is equivalent to
// source.Scan(0, (acc, current) => acc + current).TakeLast();
}
}