Write a Multiline String Literal in C#

This article will introduce a method to write a multiline string literal in C#.

  • Using the verbatim symbol

Use the verbatim symbol to write a multiline string literal in C#

In C#, we can use the verbatim symbol to create a verbatim string. A verbatim string is a string that contains multiple lines. This symbol is @. The correct syntax to use this symbol is as follows

How to Clear Multiple Textbox in VB...
How to Clear Multiple Textbox in VB.Net using Visual Studio 2015 | 2020 Best Practices
string verbatim = @" ";

The program below shows how we can use the @ symbol to write a multiline string.

using System;
using System.IO;


class MultilineString
{
    static void Main()
    {
string multiline = @"My name is Sarah.
I am a girl.
I am happy.";
Console.WriteLine(multiline);        
    }
}

Output:

My name is Sarah.
I am a girl.
I am happy.

Related Article - Csharp String

  • C# Convert String to Enum
  • C# Convert Int to String
  • Use Strings in Switch Statement in C#
  • Convert a String to Boolean in C#