Click here to Skip to main content
15,886,055 members
Articles / Programming Languages / C#

Convert half empty byte array to string?

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
16 Mar 2013CPOL 5.7K  
Hello Codeproject,Let's assume I have a byte array as follows:byte[] MainArray = new byte[4096];I then make another array out of a string:byte[] String = Encoding.ASCII.GetBytes("hello world");I then copy that array to the main array:Array.Copy(String, 0, MainArray, 0,...

Alternatives

Members may post updates or alternatives to this current article in order to show different approaches or add new features.

Please Sign up or sign in to vote.
16 Mar 2013S. M. Ahasan Habib
you can remove empty array. Your code should look like byte[] MainArray = new byte[4096]; byte[] String = Encoding.ASCII.GetBytes("hello world"); Array.Copy(String, 0, MainArray, 0, String.Length); MainArray = MainArray.Where(v => v >...
Please Sign up or sign in to vote.
16 Mar 2013OriginalGriff
Either don't send the large array - use one the size of the data you want to transfer, or prefix your actual data bytes with the number of relevant ones and only convert those at the other end.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Netherlands Netherlands
Yvar Birx;

I am fifteen years old and studied coding for about three years. I mostly code in C#, but I also have coded in Java and Visual Basic.

Comments and Discussions