Observable.ToEnumerable<TSource> メソッド
監視可能なシーケンスを列挙可能なシーケンスに変換します。
Namespace:System.Reactive.Linq
アセンブリ: System.Reactive (System.Reactive.dll)
構文
'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> 型の任意のオブジェクトでインスタンス メソッドとしてこのメソッドを呼び出すことができます。 インスタンス メソッド構文を使用してこのメソッドを呼び出す場合は、最初のパラメーターを省略します。 詳細については、」または」を参照してください。
解説
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