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

CsharpProgrammingServer Side Programming

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

The following statement

@"D:\new"

is equal to:

"D:\\new"

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
raja
Published on 08-Aug-2018 10:29:11
Advertisements