Share via


CodeNamespaceCollection.IndexOf(CodeNamespace) 方法

定義

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

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

參數

value
CodeNamespace

要尋找的 CodeNamespace

傳回

指定之 CodeNamespace 參數的索引 (如果發現它在集合中的話),否則為 -1。

範例

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

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

適用於

另請參閱