From b01b53a46dbb4d2a35c44ad2caff521f442b2741 Mon Sep 17 00:00:00 2001 From: ksami Date: Mon, 23 Oct 2017 17:36:18 +0800 Subject: clarify use case for verbatim strings added example for using @ symbol with strings --- csharp.html.markdown | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'csharp.html.markdown') diff --git a/csharp.html.markdown b/csharp.html.markdown index 963f38f4..bb8bf6e5 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"; -- cgit v1.2.3 From 3e072363d9b454973f116e39d4690ed73662f452 Mon Sep 17 00:00:00 2001 From: ksami Date: Mon, 23 Oct 2017 17:41:57 +0800 Subject: missed out the @ symbol --- csharp.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'csharp.html.markdown') diff --git a/csharp.html.markdown b/csharp.html.markdown index bb8bf6e5..77737182 100644 --- a/csharp.html.markdown +++ b/csharp.html.markdown @@ -135,7 +135,7 @@ namespace Learning.CSharp // 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"; + 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 "" -- cgit v1.2.3 From 467f143b9cc3c267d87b295e1ca84ef9308873a2 Mon Sep 17 00:00:00 2001 From: ksami Date: Mon, 23 Oct 2017 17:50:07 +0800 Subject: add example for verbatim interpolated string --- csharp.html.markdown | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'csharp.html.markdown') diff --git a/csharp.html.markdown b/csharp.html.markdown index 77737182..c98a7da9 100644 --- a/csharp.html.markdown +++ b/csharp.html.markdown @@ -955,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; } @@ -967,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"); } } -- cgit v1.2.3