Hi here is a small class made today that have array tools such as

Average
Bubble Sort
Min,Max
Swap
Sum
Reverse
Shuffle
Middle

Hope you like it comments suggestions welcome, If you think of any other cool things I can add Pm me a message and I add it in the next version.

Class code TArray.vb

vbnet Code:
  1. Option Explicit On
  2. 'My Array Tools version 1.0
  3.  
  4. Public Class TArray
  5.  
  6.     Public Function Average(ByVal Source As Object) As Integer
  7.         Dim iLen As Integer = (Source.Length - 1)
  8.         'Return average
  9.         Return Sum(Source) \ iLen
  10.     End Function
  11.  
  12.     Public Function Sum(ByVal Source As Object) As Integer
  13.         Dim iLen As Integer = (Source.Length - 1)
  14.         Dim iSum As Integer
  15.  
  16.         'Sum up values only works with numbers
  17.         For x As Integer = 0 To iLen
  18.             Try
  19.                 iSum += Source(x)
  20.             Catch ex As Exception
  21.                 iSum = 0
  22.             End Try
  23.         Next
  24.  
  25.         Return iSum
  26.     End Function
  27.  
  28.     Public Function Middle(ByVal Source As Object) As Object
  29.         Dim iLen As Integer = (Source.Length - 1)
  30.         Dim iMiddle As Integer = 0
  31.  
  32.         'Find middle in array
  33.         For x As Integer = 0 To iLen
  34.             If Source(x) < iLen Then
  35.                 iMiddle = x
  36.             End If
  37.         Next
  38.  
  39.         Return iMiddle
  40.     End Function
  41.  
  42.     Public Sub Shuffle(ByRef Source As Object)
  43.         Dim iLen As Integer = (Source.Length - 1)
  44.  
  45.         For x As Integer = 0 To iLen
  46.             Dim Seed As Integer = Int(Rnd() * x)
  47.             'Do random swap
  48.             Swap(Source(x), Source(Seed))
  49.         Next
  50.  
  51.     End Sub
  52.  
  53.     Private Sub Swap(ByRef a, ByRef b)
  54.         Dim t = b
  55.         b = a
  56.         a = t
  57.     End Sub
  58.  
  59.     Public Sub Reverse(ByRef Source As Object)
  60.         Dim iLen As Integer = (Source.Length - 1)
  61.         Dim Tmp() As Object
  62.  
  63.         ReDim Preserve Tmp(0 To iLen)
  64.  
  65.         For x As Integer = iLen To 0 Step -1
  66.             Tmp(iLen - x) = Source(x)
  67.         Next
  68.  
  69.         'Return new array.
  70.         Source = Tmp
  71.         Erase Tmp
  72.     End Sub
  73.  
  74.     Public Sub ArraySwapElement(ByVal Source As Object, ByVal iStart As Integer, ByVal iEnd As Integer)
  75.         Try
  76.             'Swap array values.
  77.             Swap(Source(iStart), Source(iEnd))
  78.         Catch ex As Exception
  79.             Throw New ArgumentException(ex.Message)
  80.         End Try
  81.     End Sub
  82.  
  83.     Public Function Max(ByRef Source As Object) As Integer
  84.         Dim MaxInt As Integer = 0
  85.         Dim iLen As Integer = (Source.Length - 1)
  86.  
  87.         For x As Integer = 0 To iLen
  88.             If Source(x) > Source(MaxInt) Then
  89.                 MaxInt = x
  90.             End If
  91.         Next
  92.  
  93.         Try
  94.             Return Source(MaxInt)
  95.         Catch ex As Exception
  96.             Return 0
  97.         End Try
  98.  
  99.     End Function
  100.  
  101.     Public Function Min(ByRef Source As Object) As Integer
  102.         Dim MinInt As Integer = 0
  103.         Dim iLen As Integer = (Source.Length - 1)
  104.  
  105.         For x As Integer = 0 To iLen
  106.             If Source(x) < Source(MinInt) Then
  107.                 MinInt = x
  108.             End If
  109.         Next
  110.  
  111.         Try
  112.             Return Source(MinInt)
  113.         Catch ex As Exception
  114.             Return 0
  115.         End Try
  116.  
  117.     End Function
  118.  
  119.     Public Sub BubbleSort(ByRef Source)
  120.         Dim iLen As Integer = Source.length
  121.  
  122.         For x As Integer = 0 To iLen
  123.             For j As Integer = x + 1 To iLen
  124.                 If Source(x) > Source(j - 1) Then
  125.                     Swap(Source(j - 1), Source(x))
  126.                 End If
  127.             Next
  128.         Next
  129.     End Sub
  130.  
  131. End Class