CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2011
    Location
    Netherlands
    Posts
    45

    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

  2. #2
    Join Date
    Mar 2004
    Location
    33°11'18.10"N 96°45'20.28"W
    Posts
    1,808

    Re: Equivalent for Dim waveform() as Byte in Visual C#

    Code:
    byte[] waveform;
    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)

  3. #3
    Join Date
    Aug 2005
    Posts
    198

    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];
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com
    Instant C# - VB to C# Converter
    Instant VB - C# to VB Converter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured