diff options
author | Shawn McGuire <bigbash@users.noreply.github.com> | 2016-06-26 07:47:36 -0500 |
---|---|---|
committer | ven <vendethiel@hotmail.fr> | 2016-06-26 14:47:36 +0200 |
commit | e9ce4e2e6e401b9bb1f495d35c57141b4cffba22 (patch) | |
tree | b2c666e9fa17698b6356d7cf2cc11332ec9ea5f5 /csharp.html.markdown | |
parent | 9d17f8bc578c96bda52bd2611625bacb8b518afb (diff) |
[csharp/en] Add string interpolation (#1864)
Added example of using string interpolation
Diffstat (limited to 'csharp.html.markdown')
-rw-r--r-- | csharp.html.markdown | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/csharp.html.markdown b/csharp.html.markdown index 8d185462..69aef257 100644 --- a/csharp.html.markdown +++ b/csharp.html.markdown @@ -8,6 +8,7 @@ contributors: - ["Wouter Van Schandevijl", "http://github.com/laoujin"] - ["Jo Pearce", "http://github.com/jdpearce"] - ["Chris Zimmerman", "https://github.com/chriszimmerman"] + - ["Shawn McGuire", "https://github.com/bigbash"] filename: LearnCSharp.cs --- @@ -947,6 +948,24 @@ on a new line! ""Wow!"", the masses cried"; A.A2(); } } + + // String interpolation by prefixing the string with $ + // and wrapping the expression you want to interpolate with { braces } + public class Rectangle + { + public int Length { get; set; } + public int Width { get; set; } + } + + class Program + { + static void Main(string[] args) + { + Rectangle rect = new Rectangle { Length = 5, Width = 3 }; + Console.WriteLine($"The length is {rect.Length} and the width is {rect.Width}"); + } + } + } // End Namespace ``` |