Express lambda expression for Func <IObserver <char>, IDisposable>
I read the following example in C # 5.0 Program. Why can I convert this lambda expression to Func<IObserver<char>, IDisposable> when it does not return IDisposable.
IObservable<char> singularHotSource = Observable.Create( (Func<IObserver<char>, IDisposable>)(obs => { while (true) { obs.OnNext(Console.ReadKey(true).KeyChar); } })); +4
1 answer
As @Patryk notes, this is basically the same as the question: βWhy is it allowed to say that it returns int when it is not?β:
int SomeMethod() { while (true) { } } And the answer; it doesnβt return something else on any code path (another type or void ) - so sure why not; the compiler can represent this as a method that returns an int .
+3