Home > DeveloperSection > Forums > Starting Index of Arrays in C# and VB.Net
jacob rasel
jacob rasel

Total Post:88

Posted on    April-08-2013 2:49 AM

 C# C# 

 1 Reply(s)
 2572  View(s)
Rate this:
Hi All!

Have a look at the following code.,


 string[] testString = new string[jobs.Count];
Equivalent VB.Net

Dim testString() As String = New String(jobs.Count - 1) {}
Why it is taking 'jobs.Count - 1' instead 'jobs.Count' in vb.net while creating new arrays?

Advance thanks!


Total Post:604

Posted on    April-08-2013 7:52 AM

Hi Jacob!

In C# the array has the number of elements you provide:

string[] array = new string[2]; // will have two element [0] and [1]
In VB.NET the array has the number of elements you provide, plus one (you specify the max index value):

Dim array(2) As String // will have three elements (0), (1) and (2)

I hope it helpful for you!

Don't want to miss updates? Please click the below button!

Follow MindStick