What does the @ prefix do on string literals in C#?


The @prefix states hat you don't need to escape special characters in the string following to the symbol.

The following statement

@"D:
ew"

is equal to:

"D:\
ew"

The @ prefix is also used if you want to have large strings and want it to be displayed across multiple lines. The following is an example showing multi-line string −

Example

 Live Demo

using System;

namespace Demo {

   class Program {

      static void Main(string[] args) {
         string str = @"Welcome User,
         Kindly wait for the image to
         load";

         Console.WriteLine(str);
      }
   }
}

Output

Welcome User,
Kindly wait for the image to
load

Updated on: 20-Jun-2020

474 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements