Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.
  • 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?

share|improve this question

migrated from stackoverflow.com Apr 10 '12 at 19:30

This question came from our site for professional and enthusiast programmers.

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

2 Answers

up vote 6 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.

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.

share|improve this answer
2  
@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
1  
@MarcGravell thanks, any idea as to why other than it not being in the spec? –  user973810 Apr 10 '12 at 19:50
1  
@dasblinkenlight: strings which prefer large government and high taxes and lots of spending for the common good. ;) –  FrustratedWithFormsDesigner Apr 10 '12 at 21:01
1  
@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
show 6 more comments

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 = @"
        Lol
    this is me
         laughing out loud
";
share|improve this answer
    
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
2  
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
1  
@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
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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