Top community members
All Wiki Articles Create Wiki Article

Welcome to Dirask IT community! ❤ 💻
We are community of people that helps each other.

If you are beginner in IT field, you are more then welcome to ask questions, it will help you to learn faster. We are here to help you.

We are always beginner in something, we just need to remember it along the way.

there are no wrong questions - Ask Question

C# / .NET - string interpolation

0 contributions
14 points

C# 6 introduced string interpolation. The main idea is similar to String.Format notation - it is just simplification and the difference is to put before string literal dolar $ sign and put each variable to curly brackets { } signs. Inside curly bracket used are same rules like in String.Format case but variable names are used instead of variable indexes put as parameters. This approach is more clear for programmers. 

String interpolation example

string name = "John";
int age = 45;
string bar = "---John---";

string text = $"My name is {name}. I am {age} y.o.\n\n{bar,29}";

Console.WriteLine(text);

Output:

My name is John. I am 45 y.o.

                   ---John---
Note: the text variable could be written as string text = String.Format("My name is {0}. I am {1} y.o.\n{2,20}", name, age, bar); according to previous approach. 

References

  1. String interpolation - Microsoft Docs
0 contributions

Suggested wiki articles:

Suggested findings

Let's do the work and have some fun
  • Dirask is online IT community for professionals and hobbyist to share their knowledge and help each other in extraordinary easy way. ❤ 💻 🙂
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    we will help you. 👍 ✔ 🦄
Read more