Custom collections - how do I enable the default property to be invoked using an index or a string?

Posted on 2006-04-03
Last Modified: 2010-05-18
Hi Experts,

You know collections that can be referenced by using either of the following syntax;

foo = myObject("itemID").value


foo = myObject(0).value

How do you do this?

At the moment I'm using the line;

Inherits ArrayList

to allow me to use the .Add(object) function and give me an enumeratable (is that a word?) object.
Question by:thefritterfatboy
    LVL 6

    Accepted Solution

    What you'd like to create is called an "indexer". You could use syntax like this to define one:

          Default Public Property Item(ByVal Index As Int32) As MyClass
                      Return something
                End Get
          End Property

          Default Public Property Item(ByVal Key As String) As MyClass
                      Return something
                End Get
          End Property

    This article gives a more detailed code sample:

    The "Item" property is what does the trick here. Documentation for

    LVL 10

    Author Comment

    Spot on, thank you!

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now