How to manipulate Arrays in VB.NET

In this artical you will learn about array and its manipulation.
  • 4090

When an array is initialized, you can access the element values and manipulate them. The foreach loop is specifically used for manipulating arrays. The foreach statement interprets the common looping process by removing the need for you to check the array size.


Foreach(type identifier in expression)

Process An Array With The foreach Loop

You  can use the following code to declare an array called Numbers, and process an array with the foreach statement, and write the values to the console, one line at the time:

        Module Module1
               Sub Main()
                    Dim Numbers As Integer() = {4, 3, 2, 1, 0, -1, -2, 9, 5}
                    Console.WriteLine("The contents of an array is :")
                    For Each K As Integer In Numbers
                    Console.Write("{0}" & vb Tab, K)
              End Sub
       End Module

The output of the preceding code is as follows:


Similar to other data types, you can also pass arrays as parameter to a method.


More Articles

© 2020 DotNetHeaven. All rights reserved.