summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndre Polykanine A.K.A. Menelion ElensĂșlĂ« <andre@oire.org>2017-10-24 02:59:50 +0300
committerGitHub <noreply@github.com>2017-10-24 02:59:50 +0300
commitd5e7aaad403a90ca594f602d231a1946baba22ef (patch)
treed97ee8c0343f1d688c2b41c53cebd2eafca9b498
parent11bd39f26aa9de4e44bc30e77bf51ebdca623bae (diff)
parent467f143b9cc3c267d87b295e1ca84ef9308873a2 (diff)
Merge pull request #2937 from ksami/ksami-csharp-strings
[csharp/en] Clarify use case for verbatim strings
-rw-r--r--csharp.html.markdown10
1 files changed, 10 insertions, 0 deletions
diff --git a/csharp.html.markdown b/csharp.html.markdown
index 963f38f4..c98a7da9 100644
--- a/csharp.html.markdown
+++ b/csharp.html.markdown
@@ -132,6 +132,12 @@ namespace Learning.CSharp
DateTime fooDate = DateTime.Now;
Console.WriteLine(fooDate.ToString("hh:mm, dd MMM yyyy"));
+ // Verbatim String
+ // You can use the @ symbol before a string literal to escape all characters in the string
+ string path = "C:\\Users\\User\\Desktop";
+ string verbatimPath = @"C:\Users\User\Desktop";
+ Console.WriteLine(path == verbatimPath); // => true
+
// You can split a string over two lines with the @ symbol. To escape " use ""
string bazString = @"Here's some stuff
on a new line! ""Wow!"", the masses cried";
@@ -949,6 +955,7 @@ on a new line! ""Wow!"", the masses cried";
// String interpolation by prefixing the string with $
// and wrapping the expression you want to interpolate with { braces }
+ // You can also combine both interpolated and verbatim strings with $@
public class Rectangle
{
public int Length { get; set; }
@@ -961,6 +968,9 @@ on a new line! ""Wow!"", the masses cried";
{
Rectangle rect = new Rectangle { Length = 5, Width = 3 };
Console.WriteLine($"The length is {rect.Length} and the width is {rect.Width}");
+
+ string username = "User";
+ Console.WriteLine($@"C:\Users\{username}\Desktop");
}
}