Share via


CompilerErrorCollection.IndexOf(CompilerError) 方法

定義

取得集合中指定之 CompilerError 物件的索引 (如果它存在於集合中的話)。

public:
 int IndexOf(System::CodeDom::Compiler::CompilerError ^ value);
public int IndexOf (System.CodeDom.Compiler.CompilerError value);
member this.IndexOf : System.CodeDom.Compiler.CompilerError -> int
Public Function IndexOf (value As CompilerError) As Integer

參數

value
CompilerError

要尋找的 CompilerError

傳回

如果找到的話,指定的 CompilerError 的索引會在 CompilerErrorCollection 中,否則為 -1。

範例

下列範例會搜尋特定 CompilerError 物件,並使用 IndexOf 方法來判斷找到它的索引值。

// Tests for the presence of a CompilerError in the
// collection, and retrieves its index if it is found.
CompilerError^ testError = gcnew CompilerError( "Testfile.cs",5,10,"CS0001","Example error text" );
int itemIndex = -1;
if ( collection->Contains( testError ) )
   itemIndex = collection->IndexOf( testError );
// Tests for the presence of a CompilerError in the
// collection, and retrieves its index if it is found.
CompilerError testError = new CompilerError("Testfile.cs", 5, 10, "CS0001", "Example error text");
int itemIndex = -1;
if( collection.Contains( testError ) )
    itemIndex = collection.IndexOf( testError );
' Tests for the presence of a CompilerError in the 
' collection, and retrieves its index if it is found.
Dim testError As New CompilerError("Testfile.cs", 5, 10, "CS0001", "Example error text")
Dim itemIndex As Integer = -1
If collection.Contains(testError) Then
    itemIndex = collection.IndexOf(testError)
End If

適用於

另請參閱