共用方式為


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

適用於

另請參閱