HttpListenerPrefixCollection.Clear 方法

定義

從集合移除所有統一資源識別元 (URI) 前置詞。

public:
 virtual void Clear();
public void Clear ();
abstract member Clear : unit -> unit
override this.Clear : unit -> unit
Public Sub Clear ()

實作

例外狀況

Windows 函式呼叫失敗。 請檢查例外狀況的 ErrorCode 屬性,以判斷造成例外狀況的原因。

與此集合相關聯的 HttpListener 已關閉。

範例

下列程式碼範例會移除 中的所有 HttpListenerPrefixCollection 前置詞。

public static bool RemoveAllPrefixes(HttpListener listener)
{
    // Get the prefixes that the Web server is listening to.
    HttpListenerPrefixCollection prefixes = listener.Prefixes;
    try
    {
        prefixes.Clear();
    }
    // If the operation failed, return false.
    catch
    {
        return false;
    }
    return true;
}
Public Shared Function RemoveAllPrefixes(ByVal listener As HttpListener) As Boolean
    ' Get the prefixes that the Web server is listening to.
    Dim prefixes As HttpListenerPrefixCollection = listener.Prefixes

    Try
        prefixes.Clear()
    Catch ' If the operation failed, return false.
        Return False
    End Try

    Return True
End Function

備註

呼叫此方法之後,您無法在未新增前置詞的情況下啟動相關聯的 HttpListener ,如果您嘗試這麼做,則會擲回例外狀況。

給呼叫者的注意事項

在應用程式中啟用網路追蹤時,這個成員會輸出追蹤資訊。 如需詳細資訊,請參閱.NET Framework中的網路追蹤

適用於

另請參閱