I would like to know how we can define multiline string literal in C#, in an easy way? For exmaple, If I have to do like this
string str= "Hello World"
+ " From India"
+ " by Rohan";
It makes difficult when we have lots of lines of string.
Multiline string liertal in C#, can be created using '@' (verbatim identifier), here is an example
string str= @"Hello World
From India
by Rohan";
Console.WriteLine(str);
Output:
Hello World
From India
by Rohan
You can also add values in the middle of multline string literal in C#, using $@ in C# 6 or above, as shown below
string text = "Customer";
string query = $@"SELECT *
FROM {text}Table
WHERE id = 007";
Console.WriteLine(query);
You may also refer to this article: Multiple ways to add newline into a String in C#
That's it, hope it helps.
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly