Mark Pearl
Mark Pearl

Reputation: 7673

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

Upvotes: 4

Views: 200

Answers (2)

Xavier Decoster
Xavier Decoster

Reputation: 14810

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

Upvotes: 2

blank
blank

Reputation: 18170

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

Upvotes: 12

Related Questions