Heredoc strings in C#

后端 未结 3 1225
再見小時候
再見小時候 2021-01-17 09:38

Is there a heredoc notation for strings in C#, preferably one where I don\'t have to escape anything (including double quotes, which are a quirk in verbatim strings

3条回答
  •  不思量自难忘°
    2021-01-17 10:12

    Well even though it doesn't support HEREDOC's, you can still do stuff like the following using Verbatim strings:

    string miniTemplate = @"
    
      Hello ""{0}"",
    
      Your friend {1} sent you this message:
    
         {2}
    
      That's all!";
    
    string populatedTemplate = String.Format(miniTemplate, "Fred", "Jack", "HelloWorld!");
    
    System.Console.WriteLine(populatedTemplate);
    

    Snagged from: http://blog.luckyus.net/2009/02/03/heredoc-in-c-sharp/

提交回复
热议问题