Created
March 3, 2020 06:03
-
-
Save decay88/6a8c04cf76696ab7471ce9134f551e24 to your computer and use it in GitHub Desktop.
Encoding.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string ToString(this byte[] bytes) | |
{ | |
char[] chars = new char[bytes.Length / sizeof(char)]; | |
Buffer.BlockCopy(bytes, 0, chars, 0, bytes.Length); | |
return new string(chars); | |
} | |
public static byte[] ToByteArray(this string @string) | |
{ | |
byte[] bytes = new byte[@string.Length * sizeof(char)]; | |
Buffer.BlockCopy(@string.ToCharArray(), 0, bytes, 0, bytes.Length); | |
return bytes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment