String To Bytes - CSharp System

CSharp examples for System:Byte

Description

String To Bytes

Demo Code


using System.Collections.Generic;
using System;/*  w w  w . j a v a 2  s.c o  m*/

public class Main{
        private static byte[] StringToBytes(string str)
        {
            byte[] bytes = new byte[str.Length * sizeof(char)];
            System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length);
            return bytes;
        }
}

Related Tutorials