--- lang: ja-jp breaks: true --- # C# `Raw string literals` `ロウ・ストリング・リテラル` 2022-08-14 > C# 11 Preview Updates – Raw string literals, UTF-8 and more! > https://devblogs.microsoft.com/dotnet/csharp-11-preview-updates/ ```csharp= var testJson = $$""" { "data": { "viewer": { "anyPinnableItems": true, "bio": null, "bioHTML": "", "commitComments": { "totalCount": 0 } } } } """; ``` ```csharp= var testJson = $$""" { "data": { "viewer": { "anyPinnableItems": true, "bio": null, "bioHTML": "", "commitComments": { "totalCount": 0 } } } } """; ``` :::warning 現時点では`csproj`に`LangVersion`の記載が必要 ```xml= <PropertyGroup> <LangVersion>Preview</LangVersion> </PropertyGroup> ``` ::: ## 以下の書き方はコンパイルエラーとなる :::warning `error CS8999: 行の先頭が生文字列リテラルの終了行と同じ空白ではありません。` ::: ```csharp= testJson = $$""" { "data": { "viewer": { "anyPinnableItems": true, "bio": null, "bioHTML": "", "commitComments": { "totalCount": 0 } } } } """; ``` ## ちなみに`// lang=json`による構文ハイライトは機能しないようだ ![](https://i.imgur.com/b1qgmBm.png) ![](https://i.imgur.com/bVhplYo.png) ###### tags: `C#` `Raw string literals` `ロウ・ストリング・リテラル`