简体   繁体   English

如何获取char类型的变量,使其值为'in c#

[英]How to get a variable of type char to have a value of ' in c#

A bit of a dumb one... but how do I get a variable of type char to have a value of ' ? 一个愚蠢的一有点...但我怎么char类型的变量有一个值'

eg 例如

char c = ''';
char a = 'A';
char b = 'B';
char c = '\'';

the backslash is called an escape character. 反斜杠称为转义字符。

and if you want a backslash it's 如果你想反斜杠那就是

char c = '\\';

Here's some more for good measure: 这里有一些更好的措施:

  • \\t - tab \\ t - 标签
  • \\n - new line \\ n - 新行
  • \\uXXXX - where XXXX is the hexadecimal value of a unicode character \\ uXXXX - 其中XXXX是unicode字符的十六进制值

char a=65 means 'A' in c++. char a = 65表示c ++中的'A'。 don't know whether it will work in c# 不知道它是否适用于c#

To complete you answer: in C#, the following statement won't compile, because you're trying to put an Int32 into a Char (no implicit casting exists) 要完成答案:在C#中,以下语句将无法编译,因为您尝试将Int32放入Char(不存在隐式转换)

char a = 65;

To convert ASCII codes to a character, you have to use the static Convert class in C#: 要将ASCII代码转换为字符,必须在C#中使用静态Convert类:

char a = Convert.ToChar(65);  // where 65 is the ascii

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM