[csharp/en] Add string interpolation (#1864)

Added example of using string interpolation
This commit is contained in:
Shawn McGuire 2016-06-26 07:47:36 -05:00 committed by ven
parent 9d17f8bc57
commit e9ce4e2e6e

View File

@ -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
```