次の方法で共有


IDebugClassField::GetDefaultIndexer

既定のインデクサーの名前を取得します。

構文

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

関連項目