Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
Hi,
 
I need to change the array item position in vb.net
 
{1,2,3,4} to {3,2,4,1}
 
Thanks,
 
Sivasankaran G
Posted 10-Jan-13 0:55am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Public Shared Sub ChangeItemPos(ByVal a As Array)
    If (a IsNot Nothing) AndAlso (a.Length > 1) AndAlso (a.Rank = 1) Then
        Dim list As New ArrayList(a)
        Dim firstItem As Object = list.Item(0)
        list.RemoveAt(0)
        For index As Integer = 1 To list.Count - 1 Step 2
            ' Swap the items
            Dim temp As Object = list.Item(index)
            list.Item(index) = list.Item(index - 1)
            list.Item(index - 1) = temp
        Next
        list.Add(firstItem) ' Put firstItem into last
        list.CopyTo(a)
    End If
End Sub
 
Example:
 
Dim a As Integer() = {1, 2, 3, 4}
ChangeItemPos(a)
  Permalink  
Comments
Sivaguru88 at 17-Jan-13 6:08am
   
Thanks for your response guna

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Dnyaneshwar@Pune 604
1 thatraja 370
2 OriginalGriff 319
3 Sergey Alexandrovich Kryukov 241
4 Gihan Liyanage 194
0 OriginalGriff 737
1 Dnyaneshwar@Pune 604
2 Kornfeld Eliyahu Peter 505
3 Sergey Alexandrovich Kryukov 372
4 thatraja 370


Advertise | Privacy | Mobile
Web03 | 2.8.140902.1 | Last Updated 10 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100