Property me()

H

Holger Kreissl

hello,
in C# you can define a property like this: public object this [string key]
So you can acess a IDictonary member by the instance that holds the hash or
what ever.. I try to get it in vb but I cant find the way. Public Property
me(ByVal key As String) As Object doesnt work like this in C# for the
property. So how is the correct syntax for that issue?

Dont work:

Public Property me(ByVal key As String) As Object
Get
If (_data.ContainsKey(key)) Then
Return _data(key)
Else
Return Nothing
End If
End Get
Set(ByVal value As Object)
SetValue(key, value)
End Set
End Property

Thanks a lot!
 
H

Holger Kreissl

OK I found that it should work like this:

class ClassName
Public Property ClassName(ByVal key As String) As Object
...

But i still get the message "cannot be indexed because it has no default
property"... But i have defined the default property or is there something
more to define?

ty
 
C

Claes Bergefall

Define it like this:

Default Public Property Item(ByVal key As String) As Object
Get
End Get
Set(ByVal value As Object)
End Set
End Property

/claes
 
H

Holger Kreissl

thanks!

Default Public Property Item(ByVal key As String) As Object
Get
End Get
Set(ByVal value As Object)
End Set
End Property

/claes
in C# you can define a property like this: public object this [string
key]
So you can acess a IDictonary member by the instance that holds the hash
or what ever.. I try to get it in vb but I cant find the way. Public
Property me(ByVal key As String) As Object doesnt work like this in C#
for the property. So how is the correct syntax for that issue?

Dont work:

Public Property me(ByVal key As String) As Object
Get
If (_data.ContainsKey(key)) Then
Return _data(key)
Else
Return Nothing
End If
End Get
Set(ByVal value As Object)
SetValue(key, value)
End Set
End Property

Thanks a lot!
 

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