String interpolation

String interpolation is a very easy and precise way to inject variable values into a string. An interpolated string expression looks at contained expressions. It then replaces those expressions with the ToString representations of the expressions' results.

Getting ready

Create a new class to test your code. We will use the example of reading the current exchange rate for a specific currency to illustrate how string interpolation can be used to output strings to the user interface.

How to do it…

  1. Create a new class by right-clicking on your solution, selecting Add, and then selecting New Project from the context menu:
    How to do it…
  2. From the Add ...

Get C# Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.