C# Tips and Tricks #9 – Multi-line String Literal in C#

C# allows the developers to have a multi-line string literal using the @ symbol in front the string. This lets the developers to form a verbatim string literal in C#.

How to display a multi-line string literal in C# ?

All that you need to do is to use the @symbol in front of the string as shown below.

string query = @”SELECT FirstName, MiddleName , LastName
FROM Employee
WHERE FirstName =’Senthil'”;

When you display this in the console window , you would notice that the string would be displayed in a multi line line.

SNAGHTML18aa496f

Here’s the code that is used.

using System;
namespace ConsoleApp1
{
    class Program
    {   
        static void Main(string[] args)
        {
            int variable1 = 10;
            Console.ReadLine();
        }
    }
}
Pin It

Leave a Reply

Your email address will not be published. Required fields are marked *