Starting Index of Arrays in C# and VB.Net

后端 未结 3 945
既然无缘
既然无缘 2020-12-11 16:57

Have a look at the following code.,

C#

 string[] testString = new string[jobs.Count];

Equivalent VB.Net

3条回答
  •  醉话见心
    2020-12-11 17:36

    Because with your C# code sample,

    string testString = new string[jobs.Count];
    

    That's a constructor of creating an array of string.

    While with the VB.Net example,

    Dim testString As String = New String(jobs.Count - 1) {}
    

    You are referring with a new String object with length of string declared in the parenthesis.

    If you want to create an array of String in VB.Net it must be like this:

    Dim testString (jobs.Count) As String
    

    see supporting links below: VB.Net C#

提交回复
热议问题