C# verbatim string literals. - CSharp Language Basics

CSharp examples for Language Basics:string

Introduction

A verbatim string literal is prefixed with @ and does not support escape sequences.

string a2 = @ "\\server\fileshare\helloworld.cs";

A verbatim string literal can also span multiple lines:

Demo Code

using System;//w ww  .  j  a  va2 s  .c o  m
class Test
{
   static void Main(){
      string escaped  = "First Line\r\nSecond Line";
      string verbatim = @"First Line
      Second Line";
      Console.WriteLine (escaped);
      Console.WriteLine (verbatim);
   }
}

Result

You can include the double-quote character in a verbatim literal by writing it twice:

Demo Code

using System;/*  w ww. j a  va2 s .co m*/
class Test
{
static void Main(){
     string xml = @"<customer id=""123""></customer>";
     Console.WriteLine (xml);
}
}

Result


Related Tutorials