C# 11 Preview: Raw String Literals

Embedding JSON, XML, or SQL in C# has always been painful (escaping quotes). Raw String Literals fix this.

var json = """
{
    "name": "John",
    "age": 30
}
""";

var sql = """
    SELECT * FROM Users
    WHERE Name = 'O''Brien'  -- No escaping needed!
""";

The number of " characters is variable (minimum 3). The content is exactly what you type.


Discover more from C4: Container, Code, Cloud & Context

Subscribe to get the latest posts sent to your email.

Leave a comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.