ParserErrorCollection.Contains(ParserError) 方法

定义

确定 ParserError 对象是否位于集合中。

public:
 bool Contains(System::Web::ParserError ^ value);
public bool Contains (System.Web.ParserError value);
member this.Contains : System.Web.ParserError -> bool
Public Function Contains (value As ParserError) As Boolean

参数

value
ParserError

要在集合中查找的 ParserError

返回

如果 ParserError 位于集合中,则为 true;否则为 false

示例

下面的代码示例演示如何在 对象中ParserErrorCollection搜索指定ParserError对象的实例。

// Test for the presence of a ParserError in the 
// collection, and retrieve its index if it is found.
ParserError testError = new ParserError("Error", "Path", 1);
int itemIndex = -1;
if (collection.Contains(testError))
  itemIndex = collection.IndexOf(testError);
' Test for the presence of a ParserError in the 
' collection, and retrieve its index if it is found.
Dim testError As New ParserError("Error", "Path", 1)
Dim itemIndex As Integer = -1
If collection.Contains(testError) Then
  itemIndex = collection.IndexOf(testError)
End If

注解

不能多次将同一 ParserError 对象添加到集合中。 但是,多次尝试添加 ParserError 对象不会引发异常。 相反,添加将失败。 在这种情况下, Add 方法将返回值 -1。 但是, AddRangeInsert 方法没有返回值。 使用下列方法之一添加 ParserError 对象时,请使用 Contains 方法确定集合中是否已存在特定 ParserError 对象。

适用于