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

适用于

另请参阅