CSharp examples for System:Byte
Converts string to byte[].
using System.Text; using System.Linq; using System.Collections.Generic; using System;/*from w w w .ja v a 2 s .co m*/ public class Main{ /// <summary> /// Converts string to byte[]. /// </summary> /// <param name="str">String to be converted</param> /// <exception cref="System.ArgumentNullException"></exception> /// <exception cref="System.Text.DecoderFallbackException"></exception> /// <returns>The byte[] that represents the string</returns> public static byte[] StringToByteArray(string str) { var encoding = new UTF8Encoding(); return encoding.GetBytes(str); } }