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

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.
Contribute
DelftStack is a collective effort contributed by software geeks like you. If you like the article and would like to contribute to DelftStack by writing paid articles, you can check the write for us page.

Related Article - Csharp String

  • Convert String to Int in C#
  • Validate Email Address in C#