|
-
February 8th, 2011, 09:41 AM
#1
Equivalent for Dim waveform() as Byte in Visual C#
Hi guys,
I am converting a program from VBS to C#, I have a problem to understand what does this line of code means. I suspect it is a kind of array but what will its best convertion form to C# I dont know.
Dim waveform() as Byte
-
February 8th, 2011, 11:15 AM
#2
Re: Equivalent for Dim waveform() as Byte in Visual C#
if you know how big you want the array (say you want it 10 elements wide):
Code:
byte[] waveform = new byte[10];
waveform[0] = 1;
waveform[1] = 255; // assign elements of the array using the [index] notation
if you need it to be dynamic you should use a list data structure instead of an array:
Code:
List<byte> waveform = new List<byte>;
waveform.Add(1);
vaveform.Add(255);// just add byte values using Add, remove using Remove(index);
byte waveformValue = waveform[1]; // access the values just like you do the array
waveform[1] = 2; // reassign an existing value the same way you do with an array (it just has to already exist)
-
February 8th, 2011, 04:08 PM
#3
Re: Equivalent for Dim waveform() as Byte in Visual C#
In addition to MadHatter's answer, be aware that array length is used in C# to specify the size, while array upper bounds are used in VB, so you have to adjust for these.
e.g.,
Code:
Dim myArray(5) As Foo
needs to convert to:
Code:
Foo[] myArray = new Foo[6];
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|