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.

Syntax

Foreach(type identifier in expression)
Statement-block

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)
                    Next
                    Console.ReadLine()
              End Sub
       End Module

The output of the preceding code is as follows:

  
4.gif

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

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.