Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clearest way to declare a char value containing a single quote/apostrophe

Tags:

c#

char

To declare a char value in C# we just surround the character with single quotes: 'x'.

But what is the "clearest" way to declare a char value that is a single quote/apostrophe?

I've ended up using "'"[0], though I had expected '''' to work (on the basis that "" can be used to delimit a quote character within a string.

Is there a sensible, more succinct option?

like image 857
Richard Ev Avatar asked Apr 28 '11 11:04

Richard Ev


People also ask

How do you use an apostrophe or single quote?

They are two entirely different punctuation symbols. Single quotes are limited to one real function in written U.S. English, which is to indicate a quotation within a quotation. Apostrophes, on the other hand, are used to denote possessive form and to indicate omission.

What is single quote in Char?

Single quotes are for single characters whereas double quotes are used to create string literals.

What is ASCII for single quote?

These are ASCII code 0x22 for double quotation mark, and ASCII code 0x27 for single quotation mark.


2 Answers

You can escape the quote with a backslash: '\''

like image 103
Blorgbeard Avatar answered Oct 03 '22 17:10

Blorgbeard


You can also use '\'' or (char)39

like image 26
PVitt Avatar answered Oct 03 '22 15:10

PVitt