LoginSignup
0
1

More than 5 years have passed since last update.

C# Conversion among string, byte[] and char[]

Posted at

C# Conversion among string, byte[] and char[]

Note to self.

string and byte

string to byte[]

> var result = Encoding.Default.GetBytes("abc");
> result
byte[3] { 97, 98, 99 }

byte[] to string

> var input = new byte[] { 0x61, 0x62, 0x63 };
> var result = Encoding.Default.GetString(input);
> result
"abc"

string and char

string to char[]

> var result = "abc".ToCharArray();
> result
char[3] { 'a', 'b', 'c' }

char[] to string

> var input = new char[] { 'a', 'b', 'c' };
> var result = new string(input);
> result
"abc"

byte and char

byte to char

Convert.ToChar Method (Byte)

char to byte

Convert.ToByte Method (Char)


Environment: Windows 10 Home, 1709, 16299.371
Visual Studio: Microsoft Visual Studio Community 2017 Version 15.6.7

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1