convert arraylist to byte

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • stephaniee
    New Member
    • Dec 2009
    • 10

    #1

    convert arraylist to byte

    Hi,

    I have created a program to get a value. This is my program code.

    Code:
     private byte getValue (byte[]ComBuffer)
               {
                    ArrayList list = new ArrayList();
                    int intVal=0;
                    for (intVal=0; intVal<129; intVal++)
                    {
                        list.Add(ComBuffer[intVal+1]);
                    }
                    return list;
                }
    When i typed these codes, i have an error message saying that "cannot implicitly convert type 'System.Collect ions.ArrayList' to 'byte"

    then when i need to use

    Code:
        void DataReceived(object sender, SerialDataReceivedEventArgs e)
            {
               
                int bytes = comPort.BytesToRead;
                byte[] comBuffer = new byte[bytes];
                comPort.Read(comBuffer, 0, bytes);
    
                getValue();
            }
    when i put the getValue method on the data received event, i have another error saying that "No overload for method 'getValue' takes '0' arguements
    Can anyone help me on this?
    Last edited by tlhintoq; Jan 27 '10, 05:34 AM. Reason: [CODE] ...Your code goes between code tags [/CODE]
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      when i put the getValue method on the data received event, i have another error saying that "No overload for method 'getValue' takes '0' arguements
      That's because the method you wrote called "getValue" requires you send it a single parameter of a byte[]
      Code:
      private byte getValue ([B][I]byte[]ComBuffer[/I][/B])
      yet you are trying to call it without sending it a byte[]
      Code:
       getValue();


      i have an error message saying that "cannot implicitly convert type 'System.Collect ions.ArrayList' to 'byte"
      You defined "list" to be of type "ArrayList"
      Code:
      ArrayList list = new ArrayList();
      yet you are trying to shove one byte out of your byte[] into one of the elements
      Code:
      list.Add(ComBuffer[intVal+1]);


      I strongly suggest you try reading about the types you are trying to use so you understand them BEFORE you just throw them into code in an effort to guess what they are by how they react. The MSDN has complete descriptions and sample code for their use. MSDN for ArrayList

      I would also suggest you start learning from a self-teaching book such as "C# in 21 days" or something similar.

      Comment

      Working...