2

I have the following working code snippet in VS2017 c#7

using system.Reactive.Linq

var combine = Observable.CombineLatest(o1, o2, (v1,v2)=> (v1,v2));

I would like to do

using static System.Reactive.Linq.Observable
var combine = CombineLatest(o1, o2, (v1,v2)=> (v1,v2));

but I get the error that

Severity Code Description Project File Line Suppression State Error CS0411 The type arguments for method 'Observable.CombineLatest<TSource>(params IObservable<TSource>[])' cannot be inferred from the usage. Try specifying the type arguments explicitly.

which is strange as I thought that using static was just syntactic sugar. Can this be made to work?

Damien_The_Unbeliever
  • 234,701
  • 27
  • 340
  • 448
bradgonesurfing
  • 30,949
  • 17
  • 114
  • 217
  • isn't observable generic class ? – Ehsan Sajjad Mar 10 '17 at 09:46
  • @EhsanSajjad: https://msdn.microsoft.com/en-us/library/system.reactive.linq.observable(v=vs.103).aspx – Chris Mar 10 '17 at 09:47
  • @EhsanSajjad No it is not. It is a static class with "Extensions methods". Extension methods may not be declared in generic classes. – Aron Mar 10 '17 at 09:47
  • Have you tried specifying the generic parameters? – Aron Mar 10 '17 at 09:51
  • Of course I could specify the generic parameters on CombineLatest but that would defeat the purpose of the excercise which is to make the code a bit tidier. – bradgonesurfing Mar 10 '17 at 09:55
  • 2
    Odd - that signature in the error message (one generic parameter, one `params` parameter) doesn't seem to match the signature [here](https://msdn.microsoft.com/en-us/library/hh211991(v=vs.103).aspx) (three generic parameters, three parameters) Could there be some other classes in play here that reuse similar names? – Damien_The_Unbeliever Mar 10 '17 at 09:56
  • the problem is that it is marked as an extension method. It is just not allowed. – bradgonesurfing Mar 10 '17 at 09:58

0 Answers0