다음을 통해 공유


Observable.Window<TSource> 메서드(IObservable<TSource>, Int32, Int32)

관찰 가능한 시퀀스의 각 요소를 요소 수 정보를 기반으로 생성되는 0개 이상의 창으로 프로젝션합니다.

네임스페이스:System.Reactive.Linq
어셈블리: System.Reactive(System.Reactive.dll)

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.

형식 매개 변수

  • TSource
    원본의 형식입니다.

매개 변수

  • skip
    형식: System.Int32
    연속 창을 만드는 동안 건너뛸 요소 수입니다.

반환 값

형식: System.IObservable<IObservable<TSource>>
관찰 가능한 창 시퀀스입니다.

사용 정보

Visual Basic 및 C#에서는 IObservable TSource> 형식의 모든 개체에서 이 메서드를 instance 메서드로 호출할 수 있습니다<. 인스턴스 메서드 구문을 사용하여 이 메서드를 호출할 경우에는 첫 번째 매개 변수를 생략합니다. 자세한 내용은 또는 를 참조하세요.

설명

Window 연산자를 사용하여 시퀀스를 시퀀스의 창 보기와 같은 버퍼링된 하위 집합으로 구분할 수 있습니다. count 매개 변수는 각 창에 배치되는 항목 수를 제어합니다. skip 매개 변수는 기본 시퀀스에서 생성된 항목을 계산하여 다음 창이 시작되는 시기를 제어합니다. 지정된 수의 항목을 건너뛰면 새 창이 시퀀스의 하위 집합을 버퍼링하기 시작합니다.

예제

이 예제에서는 Interval 연산자를 사용하여 정수의 기본 시퀀스를 생성합니다. 새 정수는 1초마다 생성됩니다. 기본 시퀀스는 Window 연산자에 의해 정수 시퀀스의 창 보기와 같은 하위 집합으로 나뉩니다. 각 창에는 첫 번째 항목(0)부터 시퀀스의 3개 항목 수가 포함됩니다. 그런 다음 5개의 항목을 건너뛰어 3개의 정수가 포함된 정수 시퀀스로 창을 만듭니다. 각 창은 5번째 정수마다 0부터 시작합니다.

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();
    }
  }
}

다음 출력은 예제 코드를 사용하여 생성되었습니다.

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

참고 항목

참조

관찰 가능한 클래스

창 오버로드

System.Reactive.Linq 네임스페이스