C# – First steps with C# and .NET – part 044.

The string interpolation feature is built on top of the composite formatting feature and provides a more readable and convenient syntax to include formatted expression results in a result string. – see documentation webpage.
In this tutorial, I will show you how can use this feature.
First, let’s see the basic example program for show a string:

If I want to use a string variable then the source code in C# will be this:

The result is this: Hello this world.
The string interpolation uses the $ sign and lets you interpolate the this_world into this way:

This embedding the variable string within the string.
If you use the dotnetfiddle online tool then you need to use the Roslyn compiler.
This is very useful because can be used like this:

I can use many variables:

Using a var like a item, see bellow:

The result is this:

Also, I can check the value with executing logic:

The result is:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.