×

VB.Net Programs

VB.Net program to demonstrate the Sort() method of Array class

By Nidhi Last Updated : November 13, 2024

Array.Sort() Method in VB.Net

The Sort() method is used to sort the specified array in ascending order.

Syntax

Sub Sort(ByVal arr() as object)

Parameter(s)

  • Arr: It is the specified integer array to be sorted.

Return Value

It does not return any value.

VB.Net code to demonstrate the example of Array.Sort() method

The source code to demonstrate the Sort() method of the Array class is given below. The given program is compiled and executed successfully.

'VB.NET program to demonstrate the Sort() method 
'of Array class.

Imports System

Module Module1
    Sub Main()
        Dim arr() As Integer = {90, 20, 70, 40, 50}

        Console.WriteLine("Original Array elements: ")
        For i = 0 To arr.Length - 1 Step 1
            Console.Write(arr(i) & " ")
        Next

        Array.Sort(arr)

        Console.WriteLine(vbCrLf & "Sorted Array elements: ")
        For i = 0 To arr.Length - 1 Step 1
            Console.Write(arr(i) & " ")
        Next

        Console.WriteLine()
    End Sub
End Module

Output

Original Array elements:
90 20 70 40 50
Sorted Array elements:
20 40 50 70 90
Press any key to continue . . .

Explanation

In the above program, we created a module Module1 that contains the Main() function. The Main() function is the entry point for the program.

In the Main() function, we created an array arr with 5 elements. After that, we sort the array in ascending order using the Sort() method and then we printed the sorted array on the console screen.

VB.Net Array Programs »


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.