CodeStatementCollection.IndexOf(CodeStatement) 方法

定義

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

C#
public int IndexOf (System.CodeDom.CodeStatement value);

參數

value
CodeStatement

要在集合中尋找的 CodeStatement

傳回

如果找到的話,就是集合中指定之物件的索引,否則為 -1。

範例

下列範例會搜尋特定 CodeStatement 是否存在,並使用 IndexOf 方法來擷取找到它的索引值。

C#
// 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 );

適用於

產品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

另請參閱