Ad space (banner)
#๏ธโƒฃC# Lessons
Lesson 46 / 68

Multi-Line Strings (Verbatim Strings)

In this lesson you will learn how to write multi-line strings in C# with verbatim strings, so you can build readable messages. This is for anyone searching for "C# multi-line string how to use".

Prefixing a string with @, as in $@"...", gives you a verbatim string that can span several lines with the line breaks included. Adding $ lets you embed variables at the same time.

The sample code assembles a three-line message - greeting, thanks, and sign-off - as one string with $@"Hello, {name}. ...". Combining it with string interpolation keeps a multi-line message with embedded variables concise.

A common stumbling block for beginners is the order and combination of @ and $. Writing $@"..." with both gives you a verbatim string and interpolation together.

In real-world development, this distinctly C# syntax is handy whenever you want to lay out something long, such as the body of an email, readably inside your code.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run C# directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)