mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 09:41:36 +00:00
[csharp/en] Add string interpolation (#1864)
Added example of using string interpolation
This commit is contained in:
parent
9d17f8bc57
commit
e9ce4e2e6e
@ -8,6 +8,7 @@ contributors:
|
|||||||
- ["Wouter Van Schandevijl", "http://github.com/laoujin"]
|
- ["Wouter Van Schandevijl", "http://github.com/laoujin"]
|
||||||
- ["Jo Pearce", "http://github.com/jdpearce"]
|
- ["Jo Pearce", "http://github.com/jdpearce"]
|
||||||
- ["Chris Zimmerman", "https://github.com/chriszimmerman"]
|
- ["Chris Zimmerman", "https://github.com/chriszimmerman"]
|
||||||
|
- ["Shawn McGuire", "https://github.com/bigbash"]
|
||||||
filename: LearnCSharp.cs
|
filename: LearnCSharp.cs
|
||||||
---
|
---
|
||||||
|
|
||||||
@ -947,6 +948,24 @@ on a new line! ""Wow!"", the masses cried";
|
|||||||
A.A2();
|
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
|
} // End Namespace
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user