Aracılığıyla paylaş


Observable.Window<TSource> Yöntemi (IObservable<TSource>, Int32, Int32)

Gözlemlenebilir bir dizinin her öğesini, öğe sayısı bilgilerine göre oluşturulan sıfır veya daha fazla pencereye projeler.

Ad Alanı:System.Reactive.Linq
Derleme: System.Reactive (System.Reactive.dll içinde)

Syntax

'Declaration
<ExtensionAttribute> _
Public Shared Function Window(Of TSource) ( _
    source As IObservable(Of TSource), _
    count As Integer, _
    skip As Integer _
) As IObservable(Of IObservable(Of TSource))
'Usage
Dim source As IObservable(Of TSource)
Dim count As Integer
Dim skip As Integer
Dim returnValue As IObservable(Of IObservable(Of TSource))

returnValue = source.Window(count, _
    skip)
public static IObservable<IObservable<TSource>> Window<TSource>(
    this IObservable<TSource> source,
    int count,
    int skip
)
[ExtensionAttribute]
public:
generic<typename TSource>
static IObservable<IObservable<TSource>^>^ Window(
    IObservable<TSource>^ source, 
    int count, 
    int skip
)
static member Window : 
        source:IObservable<'TSource> * 
        count:int * 
        skip:int -> IObservable<IObservable<'TSource>> 
JScript does not support generic types and methods.

Tür Parametreleri

  • Tsource
    Kaynak türü.

Parametreler

  • Atla
    Tür: System.Int32
    Ardışık pencere oluşturma arasında atlana öğelerin sayısı.

Dönüş Değeri

Tür: System.IObservable<IObservable<TSource>>
Gözlemlenebilir bir pencere dizisi.

Kullanım Notu

Visual Basic ve C# içinde bu yöntemi IObservable<TSource> türündeki herhangi bir nesnede örnek yöntemi olarak çağırabilirsiniz. Bu yöntemi çağırmak için örnek yöntemi sözdizimini kullandığınızda, ilk parametreyi yok sayın. Daha fazla bilgi için bkz. veya .

Açıklamalar

Window işleci, bir diziyi arabelleğe alınan alt kümelere bölmek için kullanılabilir( örneğin, sıranın pencereli görünümü). count parametresi, her pencereye yerleştirilecek öğe sayısını denetler. Skip parametresi, ana dizide üretilen öğeleri sayarak bir sonraki pencerenin ne zaman başlayacağını denetler. Belirtilen öğe sayısı atlandığında, dizinin bir alt kümesini arabelleğe almak için yeni bir pencere başlatılır.

Örnekler

Bu örnek, Interval işlecini kullanarak bir ana tamsayı dizisi oluşturur. Her saniye yeni bir tamsayı oluşturulur. Ana sıra, Window işleci tarafından tamsayı dizisinin pencereli görünümü gibi alt kümelere ayrılır. Her pencere, ilk öğeden (0) başlayarak dizideki üç öğeden oluşan bir sayı içerir. Ardından beş öğe atlandığından pencereleri üç tamsayı içeren tamsayı dizisine dönüştürebiliriz. Her pencere, 0'da başlayan her 5. tamsayı ile başlar.

using System;
using System.Reactive.Linq;
using System.Reactive.Concurrency;

namespace Example
{
  class Program
  {
    static void Main()
    {
      //***********************************************************************************************//
      //*** The mainSequence produces a new long integer from the Interval operator every second    ***//
      //*** but this sequence is broken up by the Window operator into subsets like a windowed      ***//
      //*** view of the sequence. The count parameter controls how many items are placed in each    ***//
      //*** window. The skip parameter controls when the next window starts by counting the items   ***//
      //*** produced in the main sequence. When the the specified number of items are skipped, a    ***//
      //*** new window starts.                                                                      ***//
      //***                                                                                         ***//
      //*** In this example each window will contain a count of 3 items from the sequence starting  ***//
      //*** with the first item (0). 5 items are "skipped" to determine when the next window opens. ***//
      //*** So the result is that the integer sequences in the windows start with every 5th integer ***//
      //*** beginning at 0 and include 3 integers.                                                  ***//
      //***********************************************************************************************//

      var mainSequence = Observable.Interval(TimeSpan.FromSeconds(1));

      int count = 3;
      int skip = 5;
      var seqWindowed = mainSequence.Window(count, skip);


      //*********************************************************************************************//
      //*** A subscription to seqWindowed will provide a new IObservable<long> for every 5th item ***//
      //*** in the main sequence starting with the first item.                                    ***//
      //***                                                                                       ***//
      //*** Create a subscription to each window into the main sequence and list the value.       ***//
      //*********************************************************************************************//

      Console.WriteLine("\nCreating the subscription. Press ENTER to exit...\n");
      seqWindowed.Subscribe(seqWindow =>
      {
        Console.WriteLine("\nA new window into the main sequence has been opened\n");

        seqWindow.Subscribe(x =>
        {
          Console.WriteLine("Integer : {0}", x);
        });
      });

      Console.ReadLine();
    }
  }
}

Aşağıdaki çıkış örnek kodla oluşturulmuştur.

Creating the subscription. Press ENTER to exit...


A new window into the main sequence has been opened

Integer : 0
Integer : 1
Integer : 2

A new window into the main sequence has been opened

Integer : 5
Integer : 6
Integer : 7

A new window into the main sequence has been opened

Integer : 10
Integer : 11
Integer : 12

A new window into the main sequence has been opened

Integer : 15
Integer : 16
Integer : 17

Ayrıca Bkz.

Başvuru

Gözlemlenebilir Sınıf

Pencere Aşırı Yüklemesi

System.Reactive.Linq Ad Alanı