CodeAttributeDeclarationCollection.IndexOf(CodeAttributeDeclaration) 方法

定义

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

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

参数

value
CodeAttributeDeclaration

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

返回

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

示例

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

// Tests for the presence of a CodeAttributeDeclaration in 
// the collection, and retrieves its index if it is found.
array<CodeAttributeArgument^>^temp3 = {gcnew CodeAttributeArgument( gcnew CodePrimitiveExpression( "Test Description" ) )};
CodeAttributeDeclaration^ testdeclaration = gcnew CodeAttributeDeclaration( "DescriptionAttribute",temp3 );
int itemIndex = -1;
if ( collection->Contains( testdeclaration ) )
   itemIndex = collection->IndexOf( testdeclaration );
// Tests for the presence of a CodeAttributeDeclaration in
// the collection, and retrieves its index if it is found.
CodeAttributeDeclaration testdeclaration = new CodeAttributeDeclaration("DescriptionAttribute", new CodeAttributeArgument(new CodePrimitiveExpression("Test Description")) );
int itemIndex = -1;
if( collection.Contains( testdeclaration ) )
    itemIndex = collection.IndexOf( testdeclaration );
' Tests for the presence of a CodeAttributeDeclaration in the 
' collection, and retrieves its index if it is found.
Dim testdeclaration As New CodeAttributeDeclaration("DescriptionAttribute", New CodeAttributeArgument(New CodePrimitiveExpression("Test Description")))
Dim itemIndex As Integer = -1
If collection.Contains(testdeclaration) Then
    itemIndex = collection.IndexOf(testdeclaration)
End If

适用于

另请参阅