The Special String Formatter- @ - CSharp Language Basics

CSharp examples for Language Basics:string

Introduction

To use a quote in a string, you use an escape character.

The following prints "Hello World", including quotes:

System.Console.WriteLine("\"Hello World\"");

To use a backslash, you also must use an escape character:

System.Console.WriteLine("My Code: C:\\Books\\TYCSharp\\Originals\\");

When @ precedes a string, the string's value is taken literally.

System.Console.WriteLine(@"My Code: C:\Books\TYCSharp\Originals\");

To use a double quote in a string formatted with @, you must use two double quotes.

The following is the equivalent code for the "Hello World" example:

System.Console.WriteLine(@"""Hello World!""");

Related Tutorials