-1

I am trying to convert some old legacy from VB to C# but I am running into an issue with a particular area regarding dual parentheses

Dim _atts As List(Of String()) = List(Of String())
Dim tmp() As String = Me._atts.Item(AttNo)(ValNo).Split(_SVM)

I don't understand how I would write the (attNo)(valNo) in C#

I have tried the following but with no luck

List<string[]> _atts = new List<string[]>();
string[] tmp = this._atts[attNo](valNo).Split(_SVM);

Can someone enlighten me as to what the dual parenthesis actually do in VB?

Thanks

MarkJ
  • 30,070
  • 5
  • 68
  • 111

1 Answers1

3

In VB.Net the parenthesis in this context is used to access and iterate the values of an array (access the indexer). So if you have the member variable "exampleArray" with the values {"I", "Like", "Coding"}, it can be accessed like:

VB

Dim tmpStr as String = Me.exampleArray(1); 

C#

string tmpStr = this.exampleArray[1];

now tmpStr contains the value "Like"

Now consider that you have an array "outerArray" that contains {exampleArray, someOtherArray}. If you want to get to the value "Like" you will need to index both arrays:

VB

Dim tmpStr as String = outerArray(0)(1)

C#

string tmpStr = outerArray[0][1];

The first set of square brackets (c#) or parenthesis (VB) is used to index "outerArray" to get access to "exampleArray". Then the second set of square brackets or parenthesis is used to access the value "Like" within "exampleArray".

Ref: Micorsoft Programming Guide - Arrays