0% found this document useful (0 votes)
54 views2 pages

Strings and Characters

Strings in C# begin and end with double quotes and contain text. Characters begin and end with single quotes and contain a single character. Escape sequences are used to include special characters in strings by prefixing them with a backslash. Verbatim strings declared with an @ symbol before the opening quote ignore escape sequence rules and display the string content as written.

Uploaded by

Dez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views2 pages

Strings and Characters

Strings in C# begin and end with double quotes and contain text. Characters begin and end with single quotes and contain a single character. Escape sequences are used to include special characters in strings by prefixing them with a backslash. Verbatim strings declared with an @ symbol before the opening quote ignore escape sequence rules and display the string content as written.

Uploaded by

Dez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Strings and Characters

A string begins and ends with a “double quote”. Example

string foo = "this is a string";

A Character begins and ends with a ‘single quote’. Example

char bar = 'b';

A character denotes a single character.

But we can put a single quote in a string (notice the apostrophe


at “Isn’t”. Example

string foo = "Isn't this a string?";


:ESCAPE SEQUENCES:

Escape Sequences, they begin with a backslash \ and end with a


single character.

string foo = "I asked, \"Isn't this a string\"";


---------------------------------------------------------------
:GENERATING A TAB:

To generate a tab in a sentence we add backslash \t

string foo = "I \t asked, \"Isn't this a string\"";

:GENERATING A NEWLINE:
To generate a NewLine in your code just add a backlash \n

string foo = "I \n asked, \"Isn't this a string\"";

:GENERATING A BACKSLASH:

To add a backslash \ in your string just add a double backslash

string foo = "I \\ asked, \"Isn't this a string\"";


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
:GENERATING A VERBATiM STRING:
A verbatim string is a sentence that we want displayed regardless of the rules of C#. We just
add @ symbol before the sentence, we can use this method instead of the Escape sequence:
string foo = @"I asked, ""Isn't this a string""";
Console.WriteLine(foo);

You might also like