How can I convert a Char[] (of any length) to a List ?
I have managed to use the following to get the job done:
byte[] arr = new System.Text.UTF8Encoding( true ).GetBytes( str );
List<byte> byteList = new List<byte>( arr );
Thanks for your help
First you need to understand that chars aren't bytes in .NET. To convert between chars (a textual type) and bytes (a binary type) you need to use an encoding (see System.Text.Encoding).
Encoding will let you convert between string/char[] and byte[]. Once you've got a byte array, there are various ways of converting that into a List<byte> - although you may not even need to, as byte[] implements IList<byte>.
See my article on Unicode for more about the text conversion side of things (and links to more articles).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With