One dimensional array example C#.net VB.net

One dimensional array example C#.net VB.net

Array is collection of similar types. Index of array starts with zero. Here are Vb.net and C#.net example of an array in dot net.

[C#.net] one dimensional array.

One Dimensional Array

Example uses array of integers.

using System;
namespace Csharp.RandomExample
{
class Program
{
static void Main(string[] args)
{
int[] arrayOfInteger = new int[] { 12, 4, 5, 6, 78, 98, 7 };
int length = arrayOfInteger.Length;
for (int index = 0; index < length; index++)
{
Console.WriteLine("Array element number {0} contains {1} number.", index, arrayOfInteger[index]);
}
Console.ReadLine();
}
}
}

[Vb.net] example of one dimensional array.

VB.net Program

Vb.net example uses array of integer which is one dimensional array.

Namespace Csharp.RandomExample
Class Program
Private Shared Sub Main(args As String())
Dim arrayOfInteger As Integer() = New Integer() {12, 4, 5, 6, 78, 98, _
7}
Dim length As Integer = arrayOfInteger.Length
For index As Integer = 0 To length - 1
Console.WriteLine("Array element number {0} contains {1} number.", index, arrayOfInteger(index))
Next
Console.ReadLine()
End Sub
End Class
End Namespace
Output.
Array element number 0 contains 12 number.
Array element number 1 contains 4 number.
Array element number 2 contains 5 number.
Array element number 3 contains 6 number.
Array element number 4 contains 78 number.
Array element number 5 contains 98 number.
Array element number 6 contains 7 number.

Tags:

Linq Convert String Array To Int Arrayc# arraylistC# foreach loopHow To Declare and access array of string in C#DateTimeTryParse using C# and VB.net exampleC# Get Random Item From List (VB.net) Example.C# looping through arrayRead Text File in (C#.net or VB.net)Asp.net delete file file on Server C#.net and VB.net codeASP net Write Text On Image C#.net and Vb.net programHow to select multiple columns in Linq- C#.net VB.net code

Author

My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in ASP.net year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.
 

I'm Satalaj.