C# to VB.Net

  • Thread starter Thread starter .:: MaStErDoN ::.
  • Start date Start date
M

.:: MaStErDoN ::.

Hi,
i'm "translating" som C# code to VB.net and when i need change:

const int BufferSize=10240;
byte[] buffer=new byte[BufferSize];

i try with:

Const BufferSize As Int64 = 10240

Dim buffer As Byte = New Byte(BufferSize)

But "New Byte(BufferSize) gets underlined with the error "The Byte type
doesn't have any constructor". So is it possible to change it into VB.Net.
I'm using it into an Download Manager and it's very important because Buffer
is where the program read and write de data.

If anyone knows and example of this problem with the byte or something
similar i'll be very please

Thanks! (Sorry my English, i'm Argentinian)
 
Hi Andrés,

First of all, it is better to use a type of 'Integer' for your constant and
not 'Int64'. Byte is a datatype and has no constructors so you simply
declare it as you do with any other datatype variable in VB. Your
declarations should therefore be as follows...

Const BufferSize As Integer = 10240

Dim buffer(BufferSize) As Byte


....or, if you don't need to use the 'BufferSize' constant anywhere else in
your procedure, simply get rid of it completely and just dimension the byte
array directly...

Dim buffer(10240) As Byte


Hope this helps,

Gary
 
* ".:: MaStErDoN ::. said:
i'm "translating" som C# code to VB.net and when i need change:

const int BufferSize=10240;
byte[] buffer=new byte[BufferSize];

i try with:

Const BufferSize As Int64 = 10240

Why do you use an 'Int64' here? Use 'Integer' instead.
Dim buffer As Byte = New Byte(BufferSize)

\\\
Dim buffer(BufferSize - 1) As Byte
///

This will create an array with 'BufferSize' elements with indices 0
through 'BufferSize' - 1.
 
Back
Top