How to join multiple IObservable sequences?

后端 未结 4 1468
無奈伤痛
無奈伤痛 2021-01-02 12:26
        var a = Observable.Range(0, 10);
        var b = Observable.Range(5, 10);
        var zip = a.Zip(b, (x, y) => x + \"-\" + y);
        zip.Subscribe(Conso         


        
4条回答
  •  清酒与你
    2021-01-02 12:46

    This answer is copied from the Rx forums, just so that it will be archived in here as well:

    var xs = Observable.Range(1, 10);
    var ys = Observable.Range(5, 10);
    
    var joined = from x in xs
        from y in ys
        where x == y
        select x + "-" + y;
    

    Or without using query expressions:

    var joined = 
        xs.SelectMany(x => ys, (x, y) => new {x, y})
        .Where(t => t.x == t.y)
        .Select(t => t.x + "-" + t.y);
    

提交回复
热议问题