473,414 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

convert arraylist to byte

Hi,

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

Expand|Select|Wrap|Line Numbers
  1.  private byte getValue (byte[]ComBuffer)
  2.            {
  3.                 ArrayList list = new ArrayList();
  4.                 int intVal=0;
  5.                 for (intVal=0; intVal<129; intVal++)
  6.                 {
  7.                     list.Add(ComBuffer[intVal+1]);
  8.                 }
  9.                 return list;
  10.             }
When i typed these codes, i have an error message saying that "cannot implicitly convert type 'System.Collections.ArrayList' to 'byte"

then when i need to use

Expand|Select|Wrap|Line Numbers
  1.     void DataReceived(object sender, SerialDataReceivedEventArgs e)
  2.         {
  3.  
  4.             int bytes = comPort.BytesToRead;
  5.             byte[] comBuffer = new byte[bytes];
  6.             comPort.Read(comBuffer, 0, bytes);
  7.  
  8.             getValue();
  9.         }
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?
Jan 27 '10 #1
2 4469
tlhintoq
3,525 Expert 2GB
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.
Jan 27 '10 #2
tlhintoq
3,525 Expert 2GB
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[]
Expand|Select|Wrap|Line Numbers
  1. private byte getValue (byte[]ComBuffer)
yet you are trying to call it without sending it a byte[]
Expand|Select|Wrap|Line Numbers
  1.  getValue();


i have an error message saying that "cannot implicitly convert type 'System.Collections.ArrayList' to 'byte"
You defined "list" to be of type "ArrayList"
Expand|Select|Wrap|Line Numbers
  1. ArrayList list = new ArrayList();
yet you are trying to shove one byte out of your byte[] into one of the elements
Expand|Select|Wrap|Line Numbers
  1. 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.
Jan 27 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: NoLongerMicah | last post by:
Does anyone know how the ArrayList works in regards to sizing of elements? What I mean is if you add 1,000 byte values to an ArrayList does that mean that the ArrayList is then 1,000 bytes long -...
4
by: TJO | last post by:
I am looking for an approach that would allow me to transform an ArrayList of ArrayLists into a byte and vise versa. Each item in the ArrayList is an ArrayList of Point objects which represent...
6
by: Mimi | last post by:
Is there a way to convert int to byte easily? I want to write my int indexTbl to a MemoryStream but the MemoryStream class only accepts byte buffer. I have more than one int indexTbl to write...
6
by: Petar Popara | last post by:
I need some help converting byte into Array: int bufferLen = Convert.ToInt32(file.Length); byte buffer = new byte; int len = sr.Read(buffer, 0, bufferLen); ArrayList a = new ArrayList(len);...
9
by: Charles Law | last post by:
Suppose I have a structure Private Structure MyStruct Dim el1 As Byte Dim el2 As Int16 Dim el3 As Byte End Structure I want to convert this into a byte array where
5
by: Brad | last post by:
I would like to serialize an arraylist of objects to xml so I can store the xml in a database column. How would I code the serializing and deserializing? Below is a (overly) simple, incomplete...
25
by: Charles Law | last post by:
I thought this was going to be straight forward, given the wealth of conversion functions in .NET, but it is proving more convoluted than imagined. Given the following <code> Dim ba(1) As...
7
by: millenium | last post by:
Several related questions: 1. Can an ArrayList hold a Byte or a Char ? why is this not working Dim al As ArrayList Dim ch As Char ch = "c" al.Add(ch)
0
by: JonJacobs | last post by:
When I add a series of byte arrays to an array list, then I read them back, all the arraylist byte array elements are identical to the last byte array entry. What is wrong? The following code will...
10
by: cmdolcet69 | last post by:
Public ArrList As New ArrayList Public bitvalue As Byte() Public Sub addvalues() Dim index As Integer ArrList.Add(100) ArrList.Add(200) ArrList.Add(300) ArrList.Add(400) ArrList.Add(500)
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.