We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now


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

Medium Priority
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.
Watch Question

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 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vamthItem.asp

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


Spot on, thank you!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.