字母转换成ASCII码方法
private void button1_Click(object sender, EventArgs e) { if (textBox1.Text != "") { if(Encoding.GetEncoding("unicode").GetBytes(new char[] { textBox1.Text[0] })[1] == 0) { textBox2.Text = Encoding.GetEncoding("unicode").GetBytes(textBox1.Text)[0].ToString(); } else { textBox2.Text = "请输入字母!"; } } }
ASCII码转换成字母方法
private void button2_Click(object sender, EventArgs e) { if (textBox3.Text != "") { int a; if(int.TryParse(textBox3.Text,out a)) { textBox4.Text = ((char)a).ToString(); } else { textBox4.Text = "请输入正确的ASCII码"; } } }