tags:

views:

409

answers:

4

If it's 0-based, how can we add a placeholder to make it 1-based? Thank you.

+2  A: 

it is 0 based. if you want to make it 1 based why not make a read method which accepts an index removes one and then use that and return the value?

Robert MacLean
+8  A: 

It is 0-based. A return question might be: why do you want to make it 1-based?

With Extension Methods you could (if you wanted) do:

<Extension()>
Public Function GetOneBased(Of T)(ByVal list As IList(Of T), ByVal index As Integer) As T
   Return list(index-1)
End Function

<Extension()>
Public Sub SetOneBased(Of T)(ByVal list As IList(Of T), ByVal index As Integer, ByVal value As T)
   list(index-1) = value
End Sub

then use (from almost any collection):

Dim foo = data.GetOneBased(1)
data.SetOneBased(1, bar)
Marc Gravell
Because the old code used the collection which is 1-based, so now i'm simplifying it, but if it's 0-based, there will be a huge number of statements must be modified. So...
Adam : thanks for the VB translation service ;-p
Marc Gravell
A: 

You can use Insert( int index, T item ) to insert an item at position 0, but I think you'd be better off doing index arithmetic and referencing as a 0-based collection. This is what most programmers coming after you will expect. @Robert's extension method idea has some value, but I think will end up confusing the eventual maintainers of your code.

tvanfosson
A: 

Why would you want to make it 1-based? Arrays in VB.Net used 0-based indexes as well.

Joel Coehoorn