我必须开发一个Windows Mobile C# app
来比较字符并获取ascii代码
这是我的伪代码:
public void getAscii(char c)
{
int ascii_n = c.GetAscii(); //or something that gives me the hexadec number
//You know; a=97, b=98...
if (ascii_n > 12 && ascii_n < 23)
{
//code lines
}
else if (ascii_n > 24 && ascii_n < 55)
{
//more code lines
}
}
关于我该怎么办?
答案 0 :(得分:2)
您不需要字符的十六进制表示,只需转换为整数即可
char c = '\n';
int ascii_n = (int)c;
Console.WriteLine(ascii_n); // = 10
也适用于高于255的字符
char c = '∙';
int a = (int)c;
Console.WriteLine(a); // = 8729