Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
  • Is it considered bad form? Maybe it promotes non-separate model / view?
  • Is it inefficient?
  • Was it just left out?

I guess every language has features that certain developers wish were there, and not every language can have everything. I've just always found this feature to be pretty handy. Why does .Net not have a here document syntax?


migration rejected from Dec 11 '15 at 6:47

This question came from our site for professional and enthusiast programmers. Votes, comments, and answers are locked due to the question being closed here, but it may be eligible for editing and reopening on the site where it originated.

closed as primarily opinion-based by MichaelT, GlenH7, kevin cline, Bart van Ingen Schenau, Scant Roger Dec 11 '15 at 6:47

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.If this question can be reworded to fit the rules in the help center, please edit the question.

Everywhere I've seen that feature, it's ugly. – Greg Hewgill Apr 10 '12 at 19:26
Because .NET is not a programming language. It's a framework. – BoltClock Apr 10 '12 at 19:26
up vote 8 down vote accepted

I'm assuming that by ".NET" you really mean "C#".

C# does have verbatim string literals, allowing multi-line input preserving formatting, with only a single escape concern (double-quote). If you mean "with variable interpolation" - the Mono folks have played with that - see here - but it is not a language feature of the formal c# specification. edit: they are now there in C# 6.

You could also argue that razor (and other view-template engines) is (/are) exactly this, using @x etc to signify a variable, or @(expr) for more complex examples.

@Will then we co-validate eachother. Also, I mentioned the experimental Mono stuff so: (sticks tongue out) – Marc Gravell Apr 10 '12 at 19:41
Whoa! Somebody deleted my other comment! Shennanigans! – Will Apr 10 '12 at 19:43
@MarcGravell thanks, any idea as to why other than it not being in the spec? – user973810 Apr 10 '12 at 19:50
@dasblinkenlight: strings which prefer large government and high taxes and lots of spending for the common good. ;) – FrustratedWithFormsDesigner Apr 10 '12 at 21:01
@user973810 if you mean "why isn't it a standard feature", Eric Lippert has a reply every time that question is asked: because it hasn't been fully scoped, analysed, designed, implemented, documented, tested, and deployed. Everything has cost, and every feature needs to be weighed against every other possible feature that could use the same resources, and the risk of language bloat. – Marc Gravell Apr 10 '12 at 21:29

It does. But the syntax is a little different.

Instead of << the opening delimiter is @".

You don't need to preface each line with any delimiter. That makes it simpler to type.

There is no way to change the ending delimiter. It is always ";

For example...

var foo = @"
    this is me
         laughing out loud
This isn't a HEREDOC. – FrustratedWithFormsDesigner Apr 10 '12 at 19:36
@FrustratedWithFormsDesigner: SSSSSSSSSSSSSSH! Apart from the fact that you still have to escape double quotes it is! – Will Apr 10 '12 at 19:37
If you have to escape anything, I don't think that is really the same as HEREDOC. Also, it's proper name is "verbatim string". – FrustratedWithFormsDesigner Apr 10 '12 at 19:40
@Will: your sample haiku/is missing some syllables/unfortunately. – James McLeod Apr 10 '12 at 19:41
@user973810: Oh, crap. I mean, yay! Verbatim string literals are dead useful. Use them all the time. Should probably be using resources, but that's why we have refactoring. – Will Apr 10 '12 at 19:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.