Question Re-writing a function to work in dot net 2.0

EricLucas

New member
Joined
Nov 18, 2010
Messages
2
Programming Experience
3-5
I have the following function written for dot net 3.5 that uses "ElementAt()" to successively return a value from a dictionary collection.
VB.NET:
Public Function GetNextEntryInfo() As EntryInfo
   If mFileInfo.Count > mIndexLoc Then
      Dim entry As EntryInfo = mFileInfo.ElementAt(mIndexLoc).Value
      mIndexLoc += 1
      Return entry
   Else 
      Return Nothing
   End If
End Function
Since I need this to run in dot net 2.0 I cannot use ElementAt()
I think I can re-write it like this but I'm not sure.
VB.NET:
Public Function GetNextEntryInfo() As EntryInfo
   Dim pair As KeyValuePair(Of String, EntryInformation)
   If mFileInformation.Count > mIndexLocation Then
      Dim tmpcount = 1
      For Each pair In mFileInformation
         If tmpcount < mIndexLocation Then
            tmpcount += 1
         ElseIf tmpcount = mIndexLocation Then
            mIndexLocation += 1
            Return pair.Value
         End If
      Next
   Else
      Return Nothing
   End If
End Function
Anybody know a better way to handle this?
 
So basically you need to get a value from a Dictionary by index, right?
VB.NET:
Dim values(myDictionary.Count - 1) As EntryInfo

myDictionary.Values.CopyTo(values, 0)

Dim value As EntryInfo = values(index)
 
Ah! Very good.

This is my test function - it works exactly like I wanted.
VB.NET:
Private Function GetNextEntryInfo() As String
   If myDict.Count > mIndexLoc Then
      Dim values(myDict.Count) As Integer
      myDict.Values.CopyTo(values, 0)
      Dim entry = values(mIndexLoc)
      mIndexLoc += 1
      Return entry
   Else
      Return Nothing
   End If
End Function
Thanks!
 
Back
Top