VB.NET overloading array access?

Posted by Wayne Werner on Stack Overflow See other posts from Stack Overflow or by Wayne Werner
Published on 2010-06-02T17:22:57Z Indexed on 2010/06/02 17:54 UTC
Read the original article Hit count: 318

Hi,

Is it possible to overload the array/dict access operators in VB.net? For example, you can state something like:

Dim mydict As New Hashtable()
mydict.add("Cool guy", "Overloading is dangerous!")
mydict("Cool guy") = "Overloading is cool!"

And that works just fine. But what I would like to do is be able to say:

mydict("Cool guy") = "3"

and then have 3 automagically converted to the Integer 3.

I mean, sure I can have a private member mydict.coolguy and have setCoolguy() and getCoolguy() methods, but I would prefer to be able to write it the former way if at all possible.

Thanks

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about operator-overloading