0

I have been trying to figure out how to do

object IList.this[int index]
{
    get { }
    set { }
}

public T this[int index]
{
    get { }
    set { }
}

In VB.net, and I have not been able to find anything on google.

Just to clarify, I am trying to implement the default property defined in 2 different interfaces.

Thanks :)

1 Answers1

1

The VB.NET IDE will auto-generate the implementation methods as soon as you press the Enter key after typing the Implements IFoo(Of T) statement. Producing:

Default Public Property Item(index As Integer) As T Implements IFoo(Of T).Item
    '' Get and Set...
End Property

Private Property IList_Item(index As Integer) As T Implements IList(Of T).Item
    '' Get and Set...
End Property

I had to guess at IFoo since your snippet isn't complete enough, substitute yours. It does flub on the IList.Item implementation, you have to remove the Default keyword since a class can have only one Default property (aka "indexer"). Note that in VB.NET, all interface method implementations are explicit, presumably the speed-bump. And that "Item" is the name of the indexer.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Ohh, ehm the one interface does not have an generic footprint, so only one of them has Of T, like IList(Of T) and IList. – RobinOvergaard Dec 17 '15 at 14:36
  • 1
    I'm trying to think of a reason why you would hide your code and intentionally post a shoddy snippet. As hard as I try, I can't think of one. – Hans Passant Dec 17 '15 at 14:53
  • I wasn't trying to hide my code, I was only trying to display the relevant code parts, note that the difference in the 2 properties are the type and the explicit identifier. so not to bloat the post with unrelated code. – RobinOvergaard Dec 18 '15 at 07:15
  • besides the culprit is the Default Property, since both interfaces defines a default property, vb.net complains when trying to explicitly address the 2 different default properties, which c# has no issues with. – RobinOvergaard Dec 18 '15 at 07:18