473,394 Members | 1,641 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,394 software developers and data experts.

Convert byte[] into Array?


I need some help converting byte[] into Array:

int bufferLen = Convert.ToInt32(file.Length);
byte buffer = new byte[bufferLen];
int len = sr.Read(buffer, 0, bufferLen);
ArrayList a = new ArrayList(len);
a.Add(buffer);

Array result = a.toArray();

Something like that...
Nov 17 '05 #1
6 17231
Peter,

An Array class is not the same thing as an ArrayList. When you add an
item to ArrayList, you can only access it by accessing its index. So I
believe you are looking for something like this:

byte[] byteArray = new byte[1];
byteArray[0] = 1;

ArrayList arrayList = new ArrayList(byteArray.Length);
arrayList.Add(byteArray);

byte[] someByteArray = (byte[]) arrayList[0];

Best Regards
Johann Blake

Nov 17 '05 #2
> So I
believe you are looking for something like this:


No. :(

I need Array class, because I'm using it in COM automation (SafeArray).

Something like this:

int bufferLen = Convert.ToInt32(file.Length);
char[] buffer = new char[bufferLen];
int len = sr.Read(buffer, 0, bufferLen);
byte[] tmp = new byte[0]; //Need VT_UI1 automation type. Is this OK?
Array a = Array.CreateInstance(tmp.GetType(), len);
a.SetValue(buffer);
Nov 17 '05 #3
Does this work for you?
byte[] ba = new byte[2];
Array ar = (Array)ba;

--
William Stacey [MVP]

"Petar Popara" <my*****@mail.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
So I
believe you are looking for something like this:


No. :(

I need Array class, because I'm using it in COM automation (SafeArray).

Something like this:

int bufferLen = Convert.ToInt32(file.Length);
char[] buffer = new char[bufferLen];
int len = sr.Read(buffer, 0, bufferLen);
byte[] tmp = new byte[0]; //Need VT_UI1 automation type. Is this OK?
Array a = Array.CreateInstance(tmp.GetType(), len);
a.SetValue(buffer);

Nov 17 '05 #4
Does this work for you?


Yes. :)

I'm beginner with C# and even trivial things confuses me.

Is "byte" same as "unsigned char" (BYTE) in C/C++? I need VT_UI1 automation
(compatible) type.
Nov 17 '05 #5
> Is "byte" same as "unsigned char" (BYTE) in C/C++? I need VT_UI1
automation
(compatible) type.


yes.
Nov 17 '05 #6
Hi,
What you want to do ?

your code should work changing these lines like
byte buffer = new byte[bufferLen];

a.Add(buffer);
for
byte[] buffer = new byte[bufferLen];
a.AddRange( buffer )
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Petar Popara" <my*****@mail.net> wrote in message
news:uo**************@TK2MSFTNGP12.phx.gbl...

I need some help converting byte[] into Array:

int bufferLen = Convert.ToInt32(file.Length);
byte buffer = new byte[bufferLen];
int len = sr.Read(buffer, 0, bufferLen);
ArrayList a = new ArrayList(len);
a.Add(buffer);

Array result = a.toArray();

Something like that...

Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: jeff | last post by:
how do you convert form byte to Int32 while retaining the binary value of the byte array
1
by: Swarup | last post by:
I am reading a file (txt, xml, gif, ico, bmp etc) byte by byte and filling it into a byte arry. Now i have to convert it into a string to store it in the database. I use...
6
by: Ricardo Quintanilla | last post by:
i have a code that sends data to a socket listening over as400 platform, the socket responds to me as a "byte array". then i need to convert the "byte array" into a string. the problem is that...
3
by: MuZZy | last post by:
Hi, I just wonder if someone can help me wit this - i have a byte array and need to convert it to short array, creating short numbers by combining bytes by pairs: My array: byte, byte, byte,...
15
by: Kueishiong Tu | last post by:
How do I convert a Byte array (unsigned char managed) to a char array(unmanaged) with wide character taken into account?
6
by: moondaddy | last post by:
I'm writing an app in vb.net 1.1 and need to convert a byte array into a string, and then from a string back to a byte array. for example Private mByte() as New Byte(4){11,22,33,44} Now how...
12
by: Peter | last post by:
Trying to convert string to byte array. the following code returns byte array of {107, 62, 194, 139, 64} how can I convert this string to a byte array of {107, 62, 139, 65} ...
19
by: est | last post by:
From python manual str( ) Return a string containing a nicely printable representation of an object. For strings, this returns the string itself. The difference with repr(object) is that...
5
by: da1978 | last post by:
Hi experts, I need to convert a string or a Byte array to a string byte array. Its relatively easy to convert a string to an char array or a byte array but not a STRING byte array. i.e. ...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...

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.