class with indexer is not accessible to other language

D

Duggi

Hello,

I have a class with an indexer in the class. The code code is in C#.
However I was trying to access the indexer in the other lang of .Net,
VB. I ran into some indexer related issues (I believe they are because
of indexer)

Does any one can give me procedure to do the above?

-Cnu
 
A

Alberto Poblacion

Duggi said:
I have a class with an indexer in the class. The code code is in C#.
However I was trying to access the indexer in the other lang of .Net,
VB. I ran into some indexer related issues (I believe they are because
of indexer)

Does any one can give me procedure to do the above?


When you define an indexer in C#, it is accessed from VB.Net as "Item".
For instance:

[C#]

class Whatever
{
public string this[int p]
{
get { ...; }
}
}
....
Whatever x = new Whatever();
string result = x[7];


[VB]

Dim x as New Whatever()
Dim result as String = x.Item(7)
 
D

Duggi

I have a class with an indexer in the class. The code code is in C#.
However I was trying to access the indexer in the other lang of .Net,
VB. I ran into some indexer related issues (I believe they are because
of indexer)
Does any one can give me procedure to do the above?

    When you define an indexer in C#, it is accessed from VB.Net as "Item".
For instance:

[C#]

class Whatever
{
   public string this[int p]
   {
      get { ...; }
   }}

...
Whatever x = new Whatever();
string result = x[7];

[VB]

Dim x as New Whatever()
Dim result as String = x.Item(7)

Thanks dude!!

its working.

-Cnu
 
P

Pavel Minaev

I have a class with an indexer in the class. The code code is in C#.
However I was trying to access the indexer in the other lang of .Net,
VB. I ran into some indexer related issues (I believe they are because
of indexer)
Does any one can give me procedure to do the above?

    When you define an indexer in C#, it is accessed from VB.Net as "Item".
For instance:

[C#]

class Whatever
{
   public string this[int p]
   {
      get { ...; }
   }}

...
Whatever x = new Whatever();
string result = x[7];

[VB]

Dim x as New Whatever()
Dim result as String = x.Item(7)

Actually, you should be able to just use x(7) as well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top