?
Solved

How to declare an indexer in VB.NET

Posted on 2005-02-25
4
Medium Priority
?
276 Views
Last Modified: 2008-03-17
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
Comment
Question by:datamobility
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 13402448
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
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 13402454
you this

should ofcourse be

you mean this ?

:-)
0
 
LVL 4

Accepted Solution

by:
wyoung76 earned 375 total points
ID: 13403080
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
 

Author Comment

by:datamobility
ID: 13403652
And tonight's winner of the "correct end of the stick" award goes to.....


Thanks!

.pd.
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

765 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