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

傳回

Boolean

如果 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 物件是否已經在集合中。

適用於