您需要提供索引(C#術語)或默認屬性(VB術語)。
VB::從實施例MSDN docs(myStrings
是一個字符串數組)
Default Property myProperty(ByVal index As Integer) As String
Get
' The Get property procedure is called when the value
' of the property is retrieved.
Return myStrings(index)
End Get
Set(ByVal Value As String)
' The Set property procedure is called when the value
' of the property is modified.
' The value to be assigned is passed in the argument
' to Set.
myStrings(index) = Value
End Set
End Property
和C#的語法:
public string this[int index]
{
get { return myStrings[index]; }
set { myStrings[index] = vaue; }
}