VB.NET Array Reverse Example – Code Sample Syntax
Posted by asp.net videos on Sunday, May 22, 2011 · Leave a Comment
Premium (Not Free) Video Tutorials
Free Video Tutorials & Free Tools
Premium (Not Free) Video Tutorials
Free Video Tutorials & Free Tools
VB.NET ArrayReverse Example – Code Sample Syntax
Abstract: – Illustrates using VB.NET ArrayReverse Code Example.
*** 2. ArrayReverse Syntax ***
Purpose:
Reverses the order of elements in an array
Syntax:
arrayname.Reverse
Parameters |
Description |
Parameter1 |
specifies number of elements in array
|
Result Data Type |
Description |
array |
contains a set of elements in the array in reverse order
|
*** 3. ArrayReverse – Quick Example ***
|
Dim aryAuthors(2) As String
aryAuthors(0) = “Plato”
aryAuthors(1) = “Aristotle”
aryAuthors(2) = “Hume”
Array.Reverse(aryAuthors)
|
*** 4. ArrayReverse – Full Example ***
ArrayReverse Example Output Screenshot
Step 1: Click Visual Basic to Cut-n-paste code into clsArrayReverse.vb
Public Class clsArrayReverse
Public Sub Main()
'****************************************************************************************
'
' Purpose: Reverses the order of elements in an array
'
' Syntax: arrayname.Reverse
'
' Result: array - contains a set of elements in the array in reverse order
'
' Quick Example: Dim aryAuthors(2) As String
' aryAuthors(0) = "Plato"
' aryAuthors(1) = "Aristotle"
' aryAuthors(2) = "Hume"
' Array.Reverse(aryAuthors)
'
'****************************************************************************************
' This example is from http://idealprogrammer.com
'****************************************************************************************
Console.WriteLine("Example #1: Dim aryAuthors(2) As String")
'****************************************************************************************
Dim aryAuthors(2) As String
' we start with elements in alphabetical order and then reverse
aryAuthors(0) = "Aristotle"
aryAuthors(1) = "Hume"
aryAuthors(2) = "Plato"
Array.Reverse(aryAuthors)
For Each myElement In aryAuthors
Console.WriteLine(myElement) ' Returns elements in reverse
Next
'Prevent console from closing before you press enter
Console.ReadLine()
End Sub
End Class |
Public Class clsArrayReverse
Public Sub Main()
'****************************************************************************************
'
' Purpose: Reverses the order of elements in an array
'
' Syntax: arrayname.Reverse
'
' Result: array - contains a set of elements in the array in reverse order
'
' Quick Example: Dim aryAuthors(2) As String
' aryAuthors(0) = "Plato"
' aryAuthors(1) = "Aristotle"
' aryAuthors(2) = "Hume"
' Array.Reverse(aryAuthors)
'
'****************************************************************************************
' This example is from http://idealprogrammer.com
'****************************************************************************************
Console.WriteLine("Example #1: Dim aryAuthors(2) As String")
'****************************************************************************************
Dim aryAuthors(2) As String
' we start with elements in alphabetical order and then reverse
aryAuthors(0) = "Aristotle"
aryAuthors(1) = "Hume"
aryAuthors(2) = "Plato"
Array.Reverse(aryAuthors)
For Each myElement In aryAuthors
Console.WriteLine(myElement) ' Returns elements in reverse
Next
'Prevent console from closing before you press enter
Console.ReadLine()
End Sub
End Class
Step 2: Click Visual Basic to Cut-n-paste code into Module1.vb
Module Module1
Sub Main()
Dim myclsArrayReverse As New clsArrayReverse
myclsArrayReverse.Main()
End Sub
End Module |
Module Module1
Sub Main()
Dim myclsArrayReverse As New clsArrayReverse
myclsArrayReverse.Main()
End Sub
End Module
Prerequistes:
- Install Visual Basic (Express or Standard Edition)
- Install SQL Server Express
- Download Northwind and pubs Database
- Attach Northwind Database to Databases in Sql Express
- Attach pubs Database to Databases in Sql Express
Notes:
- Console Application is used to simplify things, but Windows Forms or Web Forms could also be used
- You can build a library of syntax examples by using same project over and over and just commenting out what you do not want to execute in Module1.vb
Instructions:
- Use Visual Basic 2010 Express or Standard Edition
- Create new project;
- Click File/New Project
- Select Console Application Template
- Select Visual Basic for Language
- name of project could be VBNET_Syntax.
- Add New folder named “DataStructures”
- Right-click project name in solution explorer;
- add new folder;
- name of folder could be: DataStructures
- Add Class Named clsArrayReverse to DataStructures folder
- Right-click DataStructures folder;
- add new item;
- Select class
- Class name could be clsArrayReverse
- Click on Visual Basic in code in step 1 above to copy code into clsArrayReverse.vb
- Click on Visual Basic in code in step 2 above to copy code into Module1.vb
- Click green arrow or press F5 to run program
|