array.reverse

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Wilfredo

    array.reverse

    I have 25 numbers coming up from 1 to 25, now I want it to
    go from 25 to 1 with array.reverse. I get a reverse is not
    a member of array. Help
  • José Manuel Agüero

    #2
    Re: array.reverse

    Hello, Wilfredo:

    You have a sample of how to do that in http://msdn.microsoft.com/library/de...ssorttopic.asp.

    Regards.


    "Wilfredo" <anonymous@disc ussions.microso ft.com> escribió en el mensaje news:00b401c3b6 ab$973bd710$a40 1280a@phx.gbl.. .
    | I have 25 numbers coming up from 1 to 25, now I want it to
    | go from 25 to 1 with array.reverse. I get a reverse is not
    | a member of array. Help

    Comment

    • One Handed Man

      #3
      Re: array.reverse

      This works just fine;-

      Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
      System.EventArg s) Handles Button1.Click

      Dim myArray() As String = {"hello", "My", "Friend"}

      Dim i As Integer
      'Prints forward
      For i = 0 To myArray.Length - 1

      Debug.WriteLine (myArray(i))

      ' Next reverse array
      myArray.Reverse (myArray)

      'Prints reverse of original order using same loop as before
      For i = 0 To myArray.Length - 1

      Debug.WriteLine (myArray(i))

      Next

      End Sub

      '============== =============== ===========

      Wilfredo wrote:[color=blue]
      > I have 25 numbers coming up from 1 to 25, now I want it to
      > go from 25 to 1 with array.reverse. I get a reverse is not
      > a member of array. Help[/color]


      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: array.reverse

        * "Wilfredo" <anonymous@disc ussions.microso ft.com> scripsit:[color=blue]
        > I have 25 numbers coming up from 1 to 25, now I want it to
        > go from 25 to 1 with array.reverse. I get a reverse is not
        > a member of array.[/color]

        Sample taken from the MSDN documentation:

        \\\
        Imports System
        Imports Microsoft.Visua lBasic

        Public Class SamplesArray

        Public Shared Sub Main()

        ' Creates and initializes a new Array.
        Dim myArray As Array = Array.CreateIns tance(GetType(S tring), 9)
        myArray.SetValu e("The", 0)
        myArray.SetValu e("QUICK", 1)
        myArray.SetValu e("BROWN", 2)
        myArray.SetValu e("FOX", 3)
        myArray.SetValu e("jumped", 4)
        myArray.SetValu e("over", 5)
        myArray.SetValu e("the", 6)
        myArray.SetValu e("lazy", 7)
        myArray.SetValu e("dog", 8)

        ' Displays the values of the Array.
        Console.WriteLi ne("The Array initially contains the " _
        + "following values:")
        PrintIndexAndVa lues(myArray)

        ' Reverses the sort of the values of the Array.
        Array.Reverse(m yArray, 1, 3)

        ' Displays the values of the Array.
        Console.WriteLi ne("After reversing:")
        PrintIndexAndVa lues(myArray)
        End Sub


        Public Shared Sub PrintIndexAndVa lues(myArray As Array)
        Dim i As Integer
        For i = myArray.GetLowe rBound(0) To myArray.GetUppe rBound(0)
        Console.WriteLi ne(ControlChars .Tab + "[{0}]:" + ControlChars.Ta b _
        + "{1}", i, myArray.GetValu e(i))
        Next i
        End Sub
        End Class

        ' This code produces the following output.
        '
        ' The Array initially contains the following values:
        ' [0]: The
        ' [1]: QUICK
        ' [2]: BROWN
        ' [3]: FOX
        ' [4]: jumped
        ' [5]: over
        ' [6]: the
        ' [7]: lazy
        ' [8]: dog
        ' After reversing:
        ' [0]: The
        ' [1]: FOX
        ' [2]: BROWN
        ' [3]: QUICK
        ' [4]: jumped
        ' [5]: over
        ' [6]: the
        ' [7]: lazy
        ' [8]: dog
        ///

        --
        Herfried K. Wagner [MVP]
        <http://www.mvps.org/dotnet>

        Comment

        Working...