What is the equivalent of the VBA keyword "TO" in C #?

0

I'm passing code from vba to c # but I can not find the keyword " To " for c #
Example:

Xl = -1208721221 Xr = -38092073

Const ROUND = 16
private m_pBox(0 To ROUND + 1) As Long

Private static Sub DecryptBlock(Xl As Long, Xr As Long)
  Dim temp As Long
  temp = Xr
  Xr = Xl Xor m_pBox(ROUNDS + 1)
  Xl = temp Xor m_pBox(ROUNDS)
End Sub

And could you also explain to me what this line of code does in VBA?

    
asked by Maot 06.03.2017 в 15:32
source

2 answers

4

The following sentences ...

Const ROUND = 16
private m_pBox(0 To ROUND + 1) As Long

... equal to ...

private m_pBox(0 To 17) As Long

... which results in creating an array with 18 elements (0 to 17).

In C # there is no equivalent syntax with To for arrays since it is implicit that all arrays begin with index 0, and you just need to indicate the size of the array.

So in C #, the equivalent would be simply:

private const int ROUND = 16;
private long[] m_pBox = long[16 + 2];

... or:

private long[] m_pBox = long[18];
    
answered by 06.03.2017 / 15:50
source
1

without bad memory, this syntax is used to declare an array by value range. In your concrete case to pass it to c # you have no problem because the arrays already start at 0 and the solution that @pikoh has proposed is correct: private long[] m_pBox = new long[ROUND + 2];

    
answered by 06.03.2017 в 15:48