관찰 가능한 시퀀스를 열거 가능한 시퀀스로 변환합니다.
네임스페이스:System.Reactive.Linq
어셈블리: System.Reactive(System.Reactive.dll)
Syntax
'Declaration
<ExtensionAttribute> _
Public Shared Function ToEnumerable(Of TSource) ( _
source As IObservable(Of TSource) _
) As IEnumerable(Of TSource)
'Usage
Dim source As IObservable(Of TSource)
Dim returnValue As IEnumerable(Of TSource)
returnValue = source.ToEnumerable()
public static IEnumerable<TSource> ToEnumerable<TSource>(
this IObservable<TSource> source
)
[ExtensionAttribute]
public:
generic<typename TSource>
static IEnumerable<TSource>^ ToEnumerable(
IObservable<TSource>^ source
)
static member ToEnumerable :
source:IObservable<'TSource> -> IEnumerable<'TSource>
JScript does not support generic types and methods.
형식 매개 변수
- TSource
원본의 형식입니다.
매개 변수
- source
형식: System.IObservable<TSource>
열거 가능한 시퀀스로 변환할 관찰 가능한 시퀀스입니다.
반환 값
형식: System.Collections.Generic.IEnumerable<TSource>
관찰 가능한 시퀀스의 요소를 포함하는 열거 가능한 시퀀스입니다.
사용 정보
Visual Basic 및 C#에서는 IObservable TSource> 형식의 모든 개체에서 이 메서드를 instance 메서드로 호출할 수 있습니다<. 인스턴스 메서드 구문을 사용하여 이 메서드를 호출할 경우에는 첫 번째 매개 변수를 생략합니다. 자세한 내용은 또는 를 참조하세요.
설명
ToEnumerator 연산자는 관찰 가능한 시퀀스에서 열거자를 반환합니다. 열거자는 생성될 때 시퀀스의 각 항목을 생성합니다.
예제
다음 예제에서는 정수의 관찰 가능한 시퀀스를 만듭니다. Interval 연산자에 의해 1초마다 시퀀스에서 새 정수가 생성됩니다. 관찰 가능한 시퀀스는 열거자로 변환되고 각 항목은 생성될 때 콘솔 창에 기록됩니다.
using System;
using System.Reactive.Linq;
using System.Threading.Tasks;
namespace Example
{
class Program
{
static void Main()
{
//******************************************************//
//*** Create an observable sequence of integers. ***//
//******************************************************//
var obs = Observable.Interval(TimeSpan.FromSeconds(1));
//*******************************************************//
//*** Convert the integer sequence to an enumerable. ***//
//*******************************************************//
var intEnumerable = obs.ToEnumerable();
//*********************************************************************************************//
//*** Create a task to enumerate the items in the list on a worker thread to allow the main ***//
//*** thread to process the user's ENTER key press. ***//
//*********************************************************************************************//
Task.Factory.StartNew(() =>
{
foreach (int val in intEnumerable)
{
Console.WriteLine(val);
}
});
//*********************************************************************************************//
//*** Main thread waiting on the user's ENTER key press. ***//
//*********************************************************************************************//
Console.WriteLine("\nPress ENTER to exit...\n");
Console.ReadLine();
}
}
}
다음 출력은 예제 코드를 사용하여 생성되었습니다.
Press ENTER to exit...
0
1
2
3
4
5
6
7
8
9