开发者

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 '?

e. g.

char c = ''';
char a = 'A';
char b = 'B';
开发者_Go百科


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
  • \n - new line
  • \uXXXX - where XXXX is the hexadecimal value of a unicode character


char a=65 means 'A' in c++. don't know whether it will work in 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)

char a = 65;

To convert ASCII codes to a character, you have to use the static Convert class in C#:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜