What is @ in front of a string in C#?

It marks the string as a verbatim string literal.

In C#, a verbatim string is created using a special symbol @. @ is known as a verbatim identifier. If a string contains @ as a prefix followed by double quotes, then compiler identifies that string as a verbatim string and compile that string. The main advantage of @ symbol is to tell the string constructor to ignore escape characters and line breaks.


 Live Demo

using System;
using System.IO;
namespace DemoApplication{
   class Program{
      static void Main(string[] args){
         Console.WriteLine("test string
test string");          Console.WriteLine(@"test string
test string");          //Both the below statements are same.          string jsonString1 = File.ReadAllText(@"D:\Json.json");          string jsonString2 = File.ReadAllText("D:\Json.json");          Console.ReadLine();       }    } }


The output of the above code is as follows.

test string
test string
test string 
test string

Updated on: 04-Aug-2020

11K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started