【发布时间】:2015-10-18 03:41:55
【问题描述】:
我有这段代码,原代码here,我需要修改以在字符串列表中插入输出字符串。
我该怎么做?
private static List<string> list_of_proc = new List<string>();
static void Run<T>(Func<IObservable<T>> f, Action a)
{
Action<string> messageTarget = (x) => list_of_proc.Add(x);
using (f().Subscribe(t => Console.WriteLine(t), p => messageTarget(p)))
{
Console.ReadLine();
Console.WriteLine();
}
}
我的操作 messageTarget 没有编译。
输出错误:
这段代码编译正常,没有错误:
static void Run<T>(Func<IObservable<T>> f, Action a)
{
Action<string> messageTarget = (x) => list_of_proc.Add(x);
using (f().Subscribe(t => Console.WriteLine(t)/*, p => messageTarget(p)*/))
{
Console.ReadLine();
Console.WriteLine();
}
}
订阅有这种形式(System.Reactive.Core.dll,v2.2.5.0):
这个正确的代码:
static void Run<T>(Func<IObservable<T>> f, Action a)
{
Action<string> messageTarget = (x) => list_of_proc.Add(x);
using (f().Subscribe( t => messageTarget(t.ToString())))
{
Console.ReadLine();
Console.WriteLine();
}
}
【问题讨论】:
-
Subscribe的签名是什么?
标签: c# events system.reactive