HttpListenerPrefixCollection.GetEnumerator メソッド

定義

コレクションを反復処理するために使用できるオブジェクトを返します。

public:
 virtual System::Collections::Generic::IEnumerator<System::String ^> ^ GetEnumerator();
public System.Collections.Generic.IEnumerator<string> GetEnumerator ();
abstract member GetEnumerator : unit -> System.Collections.Generic.IEnumerator<string>
override this.GetEnumerator : unit -> System.Collections.Generic.IEnumerator<string>
Public Function GetEnumerator () As IEnumerator(Of String)

戻り値

IEnumerator インターフェイスを実装し、このコレクション内の文字列にアクセスできるようにするオブジェクト。

実装

次のコード例では、コレクションを列挙する方法を示します。 Visual Basic と C# の例では、列挙子を取得する代わりに、言語固有のステートメントを使用してコレクションを列挙することに注意してください。

public static void DisplayPrefixesAndState(HttpListener listener)
{
    // List the prefixes to which the server listens.
    HttpListenerPrefixCollection prefixes = listener.Prefixes;
    if (prefixes.Count == 0)
    {
        Console.WriteLine("There are no prefixes.");
    }
    foreach(string prefix in prefixes)
    {
        Console.WriteLine(prefix);
    }
    // Show the listening state.
    if (listener.IsListening)
    {
        Console.WriteLine("The server is listening.");
    }
}
Public Shared Sub DisplayPrefixesAndState(ByVal listener As HttpListener)
    ' List the prefixes to which the server listens.
    Dim prefixes As HttpListenerPrefixCollection = listener.Prefixes

    If prefixes.Count = 0 Then
        Console.WriteLine("There are no prefixes.")
    End If

    For Each prefix As String In prefixes
        Console.WriteLine(prefix)
    Next

    ' Show the listening state.
    If listener.IsListening Then
        Console.WriteLine("The server is listening.")
    End If
End Sub

注釈

このメソッドによって返される オブジェクトは、最初にこのコレクションの最初の要素の前に配置されます。 最初の要素に MoveNext アクセスするには、 メソッドを呼び出す必要があります。 現在の位置にある 要素にアクセスするには、 プロパティを Current 呼び出します。

列挙子の使用中にコレクションを変更しないでください。 列挙子の使用中にコレクションが変更された場合、を呼び出 MoveNext して位置を設定しようとすると、 または Reset が発生します InvalidOperationException

列挙子の詳細については、 クラスと メソッドのドキュメントをIEnumeratorGetEnumerator参照してください。

適用対象

こちらもご覧ください