HttpListenerPrefixCollection.Contains(String) 方法

定義

傳回 Boolean 值,指示集合中是否包含指定的前置詞。

public:
 virtual bool Contains(System::String ^ uriPrefix);
public bool Contains (string uriPrefix);
abstract member Contains : string -> bool
override this.Contains : string -> bool
Public Function Contains (uriPrefix As String) As Boolean

參數

uriPrefix
String

String,包含要測試的統一資源識別元 (URI) 前置詞。

傳回

如果這個集合含有由 uriPrefix 指定的前置詞,則為 true,否則為 false

實作

例外狀況

uriPrefixnull

範例

下列程式代碼範例會檢查使用者指定的前置詞是否包含在的 HttpListener前置詞集合中。

public static bool CheckForPrefix(HttpListener listener, string prefix)
{
    // Get the prefixes that the Web server is listening to.
    HttpListenerPrefixCollection prefixes = listener.Prefixes;
    if (prefixes.Count == 0 || prefix == null)
    {
        return false;
    }
    return prefixes.Contains(prefix);
}
Public Shared Function CheckForPrefix(ByVal listener As HttpListener, ByVal prefix As String) As Boolean
    Dim prefixes As HttpListenerPrefixCollection = listener.Prefixes

    ' Get the prefixes that the Web server is listening to.
    If prefixes.Count = 0 OrElse prefix Is Nothing Then
        Return False
    End If

    Return prefixes.Contains(prefix)
End Function

備註

指定的前置詞必須完全符合現有的值。

適用於

另請參閱