Visual Basic .NET - Array Function

Array.Sort: This function is used to sort the elements of an array in ascending order.

Dim arr() As Integer = {3, 5, 1, 8, 2}
Array.Sort(arr)

Array.Reverse: This function is used to reverse the order of elements in an array.

Dim arr() As Integer = {3, 5, 1, 8, 2}
Array.Reverse(arr)

Array.IndexOf: This function is used to get the index of a specific element in an array.

Dim arr() As Integer = {3, 5, 1, 8, 2}
Dim index As Integer = Array.IndexOf(arr, 8)

Array.Copy: This function is used to copy elements from one array to another.

Dim arr1() As Integer = {3, 5, 1, 8, 2}
Dim arr2(4) As Integer
Array.Copy(arr1, arr2, arr1.Length)

Array.Clear: This function is used to set all elements of an array to their default values.

Dim arr() As Integer = {3, 5, 1, 8, 2}
Array.Clear(arr, 0, arr.Length)

Array.Exists: This function is used to check if an array contains any element that satisfies a specified condition.

Dim arr() As Integer = {3, 5, 1, 8, 2}
Dim exists As Boolean = Array.Exists(arr, Function(x) x > 5)

Array.Fill: This function is used to set all elements of an array to a specific value.

Dim arr(4) As Integer
Array.Fill(arr, 5)

Array.Join: This function is used to join the elements of an array into a string, separated by a specified separator.

Dim arr() As Integer = {3, 5, 1, 8, 2}
Dim joinedString As String = String.Join("-", arr)

Array.Resize: This function is used to change the size of an array.

Dim arr(4) As Integer
Array.Resize(arr, 6)

Array.BinarySearch: This function is used to search for a specific element in a sorted array using binary search.

Dim arr() As Integer = {1, 2, 3, 5, 8}
Dim index As Integer = Array.BinarySearch(arr, 5)

Array.ConvertAll: This function is used to convert an array of one data type to another data type.

Dim arr() As String = {"3", "5", "1", "8", "2"}
Dim arrInt() As Integer = Array.ConvertAll(arr, Function(x) Integer.Parse(x))

Array.TrueForAll: This function is used to check if all elements of an array satisfy a specified condition.

Dim arr() As Integer = {3, 5, 1, 8, 2}
Dim allGreater As Boolean = Array.TrueForAll(arr, Function(x) x > 0)