共用方式為


CodeTypeDeclarationCollection.IndexOf(CodeTypeDeclaration) 方法

定義

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

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

參數

value
CodeTypeDeclaration

要在集合中尋找的 CodeTypeDeclaration

傳回

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

範例

下列範例會 CodeTypeDeclarationCodeTypeDeclarationCollection 物件擷取專案,並顯示方法傳 IndexOf 回的名稱和索引。

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

適用於

另請參閱