Convert string to byte array with for loop

image_pdfimage_print

using System;

public sealed class Strings
{

public static byte[] ToByteArray(string s)
{
byte[] bs = new byte[s.Length];
for (int i = 0; i < bs.Length; ++i) { bs[i] = Convert.ToByte(s[i]); } return bs; } } [/csharp]

This entry was posted in Data Types. Bookmark the permalink.