简体   繁体   中英

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

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
  • \\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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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