Stuart M
Stuart M

Reputation: 43

C# to VB.net Byte Conversions

I'm trying to use some code from the Opus project in VB.net, it was originally written for C, but I am integrating it into another application...

    byte[] _notEncodedBuffer = new byte[0];

    byte[] soundBuffer = new byte[e.BytesRecorded + _notEncodedBuffer.Length];

I'm not sure how these should be translated into VB.net, I have translated all the code but this and am getting good results, just not entirely sure on these, had all kinds of errors with my attempts, including Identifier expected, Bracket identifier missing etc! :(

    Dim wavNEB As Byte() = New Byte [0]

    Dim wavSnd As Byte() = New Byte [e.BytesRecorded + wavNEB.Length]

That was my last attempt, but no cigar!

Any help much appreciated, I rarely have to break VB or C out so it's not a strong point...

Upvotes: 2

Views: 430

Answers (1)

supercat
supercat

Reputation: 81105

In VB.NET, the syntax

Dim ArrayName(N) As ArrayType

is equivalent to the C# code:

ArrayType[] ArrayName = new ArrayType[N+1];

Additionally, if ArrayName has been declared as ArrayType, the executable statement

ReDim ArrayName(N)

would be equivalent to the C# code

ArrayName = new ArrayType[N+1];

Additionally, VB.NET offers the syntax

ReDim Preserve ArrayName(N)

as a means of replacing ArrayName with a reference to a new array of size N+1 whose contents are pre-loaded with those of the old array.

Upvotes: 6

Related Questions