C#/.NET uses Unicode characters, so the €
sign is 8364
.
You can check that with:
int val = (int)'€'; // val will be 8364
This also means you can not represent a char
as one byte
as most of them need 2 bytes.
If you want to use the extended ASCII table you can use Encoding.Default
:
var valStr = Encoding.Default.GetString(new byte[] { 128 }); // valStr = €
var valByte = Encoding.Default.GetBytes("€"); // valByte[0] = 128
Encoding.Default
uses the current ANSI code page (see Joe's answer or Jeppe's comment to choose a specific one) and Encoding.ASCII
uses the 7-bit ASCII table, so there is no 128
in ASCII
.