TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

<< Back to VBNET

VB.NET Array.Reverse Example

Use the Array.Reverse subroutine to invert the order of elements.
Array.Reverse inverts the order of elements. It can act upon an entire array, or just part of an array (a range). It can be used to sort in reverse—simply call Reverse after Sort.Array
An example. Let's begin with this program. The initial array is pointed to by the reference variable a. Then, we reverse that array with Array.Reverse(a). The return value is not used.Integer

Finally: We reverse only the first two elements by using the parameters 0 (the first index) and 2 (the count of elements to reverse).

Tip: Reverse is found on the Array type. It is a static (shared) function. We call it with a composite name.

Shared
VB.NET program that reverses array Module Module1 Sub Main() Dim a() As Integer = {1, 4, 6, 10} For Each v As Integer In a Console.WriteLine(v) Next Console.WriteLine() ' Reverse entire array. Array.Reverse(a) For Each v As Integer In a Console.WriteLine(v) Next Console.WriteLine() ' Reverse part of array. Array.Reverse(a, 0, 2) For Each v As Integer In a Console.WriteLine(v) Next End Sub End Module Output 1 4 6 10 10 6 4 1 6 10 4 1
A discussion. The implementation of .NET methods is relevant because it tells us whether they will be efficient. Array.Reverse calls an internal method called TrySZReverse.

Tip: This is in unmanaged code. It is likely faster in most situations because of unmanaged optimizations.

Reverse string. With Array.Reverse we can reverse the ordering of chars in a string. We first use ToCharArray to convert a string to a char array.Reverse String
A summary. We reverse an entire array or only parts (ranges) of an array with Array.Reverse. The type of the elements in the array are not important—they are not sorted or changed.
An internal method. Array.Reverse uses an internal, optimized method. It would be hard to develop a faster one in VB.NET code. Usually this built-in is preferred.
© TheDeveloperBlog.com
The Dev Codes

Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf