共用方式為


IDebugClassField::GetDefaultIndexer

取得預設索引子的名稱。

HRESULT GetDefaultIndexer( 
   BSTR* pbstrIndexer
);
int GetDefaultIndexer(
   out string pbstrIndexer
);

參數

  • pbstrIndexer
    [] out傳回字串,包含預設索引子的名稱。

傳回值

如果成功的話,會傳回 S_OK,或傳回 S_FALSE,如果沒有預設索引子。 否則,會傳回錯誤碼。

備註

類別的預設索引子是屬性標記為Default陣列存取的屬性。 這僅適用於Visual Basic。 以下是範例中所宣告的預設索引子的Visual Basic ,以及如何使用它。

Imports System.Collections;

Public Class Class1
    Private myList as Hashtable

    Default Public Property Item(ByVal Index As Integer) As Integer
        Get
            Return CType(List(Index), Integer)
        End Get
        Set(ByVal Value As Integer)
            List(Index) = Value
        End Set
    End Property
End Class

Function GetItem(Index as Integer) as Integer
    Dim classList as Class1 = new Class1
    Dim value as Integer

    ' Access array through default indexer
    value = classList(2)

    ' Access array through explicit property
    value = classList.Item(2)

    Return value
End Function

請參閱

參考

IDebugClassField