这么写就行,C#和C语言一样int和char是可以相互转换的
private void button1_Click(object sender, EventArgs e)
{
int i = 'A';
MessageBox.Show("A的ASCII码是:" + i.ToString());
int j = 78;
MessageBox.Show("ASCII码78对应的字符是:" + (char)j);
}
private void TestChar() {
char ch = ''a''; short ii = 65;
this.textBox1.Text = "";
this.textBox1.AppendText("The ASCII code of \''" + ch + "\'' is: " + (short) ch + "\n");
this.textBox1.AppendText("ASCII is " + ii.ToString() + ", the char is: " + (char) ii + "\n");
char cn = ''中''; short uc = 22478;
this.textBox1.AppendText("The Unicode of \''" + cn + "\'' is: " + (short) cn + "\n");
this.textBox1.AppendText("Unicode is " + uc.ToString() + ", the char is: " + (char) uc + "\n");
}
它的运行结果是
The ASCII code of ''a'' is: 97
ASCII is 65, the char is: A
The Unicode of ''中'' is: 20013
Unicode is 22478, the char is: 城