• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 282
  • Last Modified:

How to declare an indexer in VB.NET

In C# I can do this:

public string this[int idx]
{
  get { return (string) lookupItem(idx); }
}

How can I do that in VB?  

Cheers,
.pd.
0
datamobility
Asked:
datamobility
  • 2
1 Solution
 
RonaldBiemansCommented:
you this ?

dim mystring as string =" test"

public function charstring(mystring as as string,index as integer) as char
   return mystring.chars(index)
end function

or just

dim mychar as char = mystring.chars(3)
0
 
RonaldBiemansCommented:
you this

should ofcourse be

you mean this ?

:-)
0
 
wyoung76Commented:
Perhaps what the author means is something like a default property?

== Torn directly from the MSDN docs ==

' Visual Basic
' A class that contains many Widgets
Public Class Widgets
   'Default property implementation
   Default Public Property Widget(ByVal I As Integer) As Widget
      Get
      ' Implementation code to return a widget goes here.
      End Get
      Set(ByVal Value As Widget)
      ' Implementation code to set a widget goes here.
      End Set
   End Property
End Class

// C#
// Class that contains many Widgets.
public class Widgets
{
   // Indexer implementation.
   public Widget this[int index]
   {
      get
      {
         // Insert code to return a Widget.
      }
      set
      {
         // Insert code to set a Widget.
      }
   }
}

====

Hopefully I've interpreted this correctly, and have got the correct end of the stick  :o)
0
 
datamobilityAuthor Commented:
And tonight's winner of the "correct end of the stick" award goes to.....


Thanks!

.pd.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now