Internetwork Consulting LLC
3880 Greenhouse Road #421
Houston, TX 77084

832-606-3300

sales@internetworkconsulting.net
Custom Software Development - Computer Repair
 

How to Override the Index Operator

To index an array in C# we can use the following:

object collection_item = collection_instance[index];

We can add the array indexing to a class by the following:

class some_class {

private List<object> arr = new List<object>();

public override object this[int index] {

return arr[index];

}

}

The question then becomes, how we do the same thing in Visual Basic. The answer is to override the Index() function:

Public Class some_class

Private arr As List(Of object) = new List(Of object)()

Default Public ReadOnly Property Item(index As Integer) As Object

Get

Return arr(index)

End Get

End Property

End Class