C# MultiLine strings (c sharp)

Well I lost my way when recently try to assign a value to string variable. This is one mistake that I make again and again. Being doing programming in other languages, those which handle strings differently it is obvious to stuff up simple things when you switch language for your next project.

Here is what I tried to allocate

[geshi lang=”csharp” nums=”1″ target=”_self” ]

string myVar = “Correct Usage
myapp.exe [-options]”;

This will result in a compiler error. Now because I love an operator that Microsoft introduced as while back which is called @. So sleek yet so powerful when working with string. Now if you prepend the above with @ the error dissappears.

[geshi lang=”csharp” nums=”1″ target=”_self” ]

string myVar = @”Correct Usage
myapp.exe [-options]”;

You can also do something similar to this.

[geshi lang=”csharp” nums=”1″ target=”_self” ]

string myVar = “Correct Usage”+
“myapp.exe [-options]”;

I prefer using @ because it present cleanness to the string and I think the string is more readable.

I hope this helps

 

Leave a Reply

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