CodeExpressionCollection.IndexOf(CodeExpression) 方法

定义

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

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

参数

value
CodeExpression

要在集合中定位的 CodeExpression 对象。

返回

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

示例

以下示例搜索特定 CodeExpression 对象的存在,并使用 IndexOf 方法获取找到该对象的索引值。

// Tests for the presence of a CodeExpression in the 
// collection, and retrieves its index if it is found.
CodeExpression^ testComment = gcnew CodePrimitiveExpression( true );
int itemIndex = -1;
if ( collection->Contains( testComment ) )
   itemIndex = collection->IndexOf( testComment );
// Tests for the presence of a CodeExpression in the
// collection, and retrieves its index if it is found.
CodeExpression testComment = new CodePrimitiveExpression(true);
int itemIndex = -1;
if( collection.Contains( testComment ) )
    itemIndex = collection.IndexOf( testComment );
' Tests for the presence of a CodeExpression in the 
' collection, and retrieves its index if it is found.
Dim testComment = New CodePrimitiveExpression(True)
Dim itemIndex As Integer = -1
If collection.Contains(testComment) Then
    itemIndex = collection.IndexOf(testComment)
End If

适用于

另请参阅