[RESOLVED] [2.0] String from List<byte>
I have a List of bytes that I want to convert to a string. Currently I am doing this:
Code:
// myList is a generic List<byte>
string myString = "";
foreach (byte byt in myList)
{
myString += (char)byt;
}
ConsoleWriteLine(myString);
Is there a better alternative I can use that will convert all the bytes in one go without the foreach loop?
At the moment the list will hold a max. of around 25 bytes.
Re: [2.0] String from List<byte>
This is untested but I think it should work:
vb Code:
string myString = System.Text.Encoding.ASCII.GetString(myList.ToArray());
Re: [2.0] String from List<byte>
Quote:
Originally Posted by jmcilhinney
I think it should work
Spot on. :thumb:
Thanks.