gpt4 book ai didi

c# - react X : Catching exceptions on Observable as lambda expression

转载 作者:行者123 更新时间:2023-11-30 20:28:31 37 4
gpt4 key购买 nike

我有这样的观察:

public class NetworkToolEngine
{
public NetworkToolEngine()
{
this.connectionAvailable = Observable
.Interval(TimeSpan.FromSeconds(5))
.Select(_ => true);
}
}

static class Program
{
static void Main()
{
NetWorkToolEngine networkToolEngine = new NetworkToolEngine();
this.networkToolEngine.ConnectionAvailable
.Do(_ => this.ConnectionAvailable())
.Catch(ex => //<<<<<1>>>>>
{
this.ConnectionUnavailable();
return Observable.Empty<bool>();
});
}

目前;我在 <<<<<1>>>>> 处收到此编译错误:

Cannot convert lambda expression to type 'IObservable' because it is not a delegate type

有什么想法吗?

最佳答案

这是因为 catch 存在多个重载,并且您没有指定 ex 的类型 - 它会选择错误的类型。你需要这样做:

.Catch((Exception ex) =>    //<<<<<1>>>>>
{
this.ConnectionUnavailable();
return Observable.Empty<bool>();
});

关于c# - react X : Catching exceptions on Observable<bool> as lambda expression,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47203386/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com