CodeStatementCollection.IndexOf(CodeStatement) 方法

定义

获取指定的 CodeStatement 对象在 CodeStatementCollection 中的索引(如果它已存在于该集合中)。

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

参数

value
CodeStatement

要在集合中查找的 CodeStatement

返回

如果在该集合中找到指定对象,则为此对象在该集合中的索引;否则为 –1。

示例

以下示例搜索是否存在特定 CodeStatement ,并使用 IndexOf 方法检索找到它的索引值。

// Tests for the presence of a CodeStatement in the 
// collection, and retrieves its index if it is found.
int itemIndex = -1;
if ( collection->Contains( testStatement ) )
   itemIndex = collection->IndexOf( testStatement );
// Tests for the presence of a CodeStatement in the
// collection, and retrieves its index if it is found.
int itemIndex = -1;
if( collection.Contains( testStatement ) )
    itemIndex = collection.IndexOf( testStatement );
' Tests for the presence of a CodeStatement in the 
' collection, and retrieves its index if it is found.
Dim itemIndex As Integer = -1
If collection.Contains(testStatement) Then
    itemIndex = collection.IndexOf(testStatement)
End If

适用于

另请参阅