HttpListenerPrefixCollection.GetEnumerator 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
컬렉션을 반복하는 데 사용할 수 있는 개체를 반환합니다.
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.
열거자에 대한 자세한 설명은 클래스 및 GetEnumerator 메서드에 IEnumerator 대한 설명서를 참조하세요.
적용 대상
추가 정보
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기