Skip to content

Instantly share code, notes, and snippets.

@ahmetabdi
Created February 8, 2016 13:21
Show Gist options
  • Save ahmetabdi/b1a0ec09a13166d288ae to your computer and use it in GitHub Desktop.
Save ahmetabdi/b1a0ec09a13166d288ae to your computer and use it in GitHub Desktop.
DLL to byte [], byte [] to String, String to byte []
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.IO;
namespace ConsoleApplication
{
public class Program
{
public void Main(string[] args)
{
Console.WriteLine(Path.GetTempPath());
string dllPath = String.Format("{0}/PigDll.dll", Path.GetTempPath());
// From Dll to byte array
byte[] buffer = System.IO.File.ReadAllBytes(dllPath);
// From byte array to string
string s = System.Text.Encoding.UTF8.GetString(buffer, 0, buffer.Length);
// From string to byte array
byte[] buffer2 = System.Text.Encoding.UTF8.GetBytes(s);
Console.WriteLine(buffer2.Length);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment