(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Array.Reverse a string array
Imports System.Collections
public class Test
public Shared Sub Main
Dim StringArray() As String = {"This", "is", "a", "test"}
Array.Reverse(StringArray)
Dim E As IEnumerator = StringArray.GetEnumerator()
While (E.MoveNext())
Console.WriteLine(E.Current())
End While
End Sub
End class
test
a
is
This
Array.Sort a string array
Imports System.Collections
public class Test
public Shared Sub Main
Dim StringArray() As String = {"This", "is", "a", "test"}
Array.Sort(StringArray)
Dim E As IEnumerator = StringArray.GetEnumerator()
While (E.MoveNext())
Console.WriteLine(E.Current())
End While
End Sub
End class
a
is
test
This
Store data in a multivalue array
Public Class Tester
Public Shared Sub Main
Dim multiValue(2)() As String
Dim counter1 As Integer
Dim counter2 As Integer
" ----- Build the multivalue array.
multiValue(0) = New String() {"alpha", "beta", "gamma"}
multiValue(1) = New String() {"A", "B", "C", "D", "E", "F", "G", "H"}
multiValue(2) = New String() {"Yes", "No"}
" ----- Format the array for display.
For counter1 = 0 To multiValue.Length - 1
For counter2 = 0 To multiValue(counter1).Length - 1
Console.WriteLine(multiValue(counter1)(counter2))
Next counter2
Console.WriteLine("")
Next counter1
End Sub
End Class
alpha
beta
gamma
A
B
C
D
E
F
G
H
Yes
No
String array
Module Test
Public Sub Main()
Dim sMonths() As String = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", Oct", "Nov", "Dec"}
Console.WriteLine("Eleventh month of the year = {0}", sMonths(10))
End Sub
End Module
Eleventh month of the year = Nov
Two dimensional string array
public class Test
public Shared Sub Main
Dim str_values(,,) As String = _
{ _
{ _
{"000", "001", "002"}, _
{"010", "011", "012"} _
}, _
{ _
{"100", "101", "102"}, _
{"110", "111", "112"} _
} _
}
Console.WriteLine("")
For i As Integer = 0 To 1
For j As Integer = 0 To 1
For k As Integer = 0 To 2
Console.Write(str_values(i, j, k) & " ")
Next k
Next j
Console.WriteLine("")
Next i
End Sub
End class
000 001 002 010 011 012
100 101 102 110 111 112
Use For Each Loop to output a String array
Public Class Tester
Public Shared Sub Main
Dim fruitArray() As String = {"Oranges", "Apples", "Grapes", "Bananas", "Blueberries"}
For Each fruit As String In fruitArray
Console.WriteLine(fruit)
Next fruit
End Sub
End Class
Oranges
Apples
Grapes
Bananas
Blueberries