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
Printable View
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
if you know how big you want the array (say you want it 10 elements wide):Code:byte[] waveform;
if you need it to be dynamic you should use a list data structure instead of an array:Code:byte[] waveform = new byte[10];
waveform[0] = 1;
waveform[1] = 255; // assign elements of the array using the [index] notation
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)
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.,
needs to convert to:Code:Dim myArray(5) As Foo
Code:Foo[] myArray = new Foo[6];