HttpListenerPrefixCollection.Contains(String) 方法

定义

返回一个 Boolean 值,该值指示指定的前缀是否包含在该集合中。Returns a Boolean value that indicates whether the specified prefix is contained in the collection.

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) 前缀。A String that contains the Uniform Resource Identifier (URI) prefix to test.

返回

Boolean

如果此集合包含由 uriPrefix 指定的前缀,则为 true;否则为 falsetrue if this collection contains the prefix specified by uriPrefix; otherwise, false.

实现

例外

uriPrefixnulluriPrefix is null.

示例

下面的代码示例检查是否在的前缀集合中包含用户指定的前缀 HttpListenerThe following code example checks to see whether a user-specified prefix is contained in the prefix collection of an 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

注解

指定的前缀必须与现有的值完全匹配。The specified prefix must exactly match an existing value.

适用于

另请参阅