locked
how to read Next or Previews value in array? RRS feed

  • Question

  • in array with EF how to read next or prev value?

    dim myarray() as string
    dim query=from q in myarray where q = "HD2011-1010"
    'query.next
    

    sorry for my bad english

    Saturday, December 17, 2011 9:09 AM

Answers

  • It looks like you are trying to use LINQ to find the index of "HD2011-1010", but I'm not sure LINQ is the easiest way to do that.  Instead, you might consider something like this:

    Module Module1
    
        Sub Main()
            Dim myarray() As String = {"HD2011-1009", "HD2011-1010", "HD2011-1011", "HD2011-1012"}        
            Dim indexOfInterest As Integer = Array.IndexOf(myarray, "HD2011-1010")
            Dim prevIndex As Integer = indexOfInterest - 1
            Dim prevElement As String = myarray(prevIndex)
            Dim nextIndex As Integer = indexOfInterest + 1
            Dim nextElement As String = myarray(nextIndex)
            System.Console.WriteLine("NextElement is " & nextElement)
            System.Console.WriteLine("PreviousElement is " & prevElement)
        End Sub
    
    End Module
    

    Best,

    Shawn

    Saturday, December 17, 2011 9:48 AM

All replies

  • It looks like you are trying to use LINQ to find the index of "HD2011-1010", but I'm not sure LINQ is the easiest way to do that.  Instead, you might consider something like this:

    Module Module1
    
        Sub Main()
            Dim myarray() As String = {"HD2011-1009", "HD2011-1010", "HD2011-1011", "HD2011-1012"}        
            Dim indexOfInterest As Integer = Array.IndexOf(myarray, "HD2011-1010")
            Dim prevIndex As Integer = indexOfInterest - 1
            Dim prevElement As String = myarray(prevIndex)
            Dim nextIndex As Integer = indexOfInterest + 1
            Dim nextElement As String = myarray(nextIndex)
            System.Console.WriteLine("NextElement is " & nextElement)
            System.Console.WriteLine("PreviousElement is " & prevElement)
        End Sub
    
    End Module
    

    Best,

    Shawn

    Saturday, December 17, 2011 9:48 AM
  • Thanks - fixed it now! Great Suggestion.
    Saturday, December 17, 2011 10:07 AM