STARTING INDEX OF ARRAYS IN C# AND VB.NET

jacob rasel

Total Post:88

Points:616
Posted by  jacob rasel
C# 
C#
 2652  View(s)
Ratings:
Rate this:
Hi All!

Have a look at the following code.,

C#

 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!
  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: Starting Index of Arrays in C# and VB.Net

    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!

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!