C# – String Concatenation & String Interpolation


Zephaniah 3:17 (NIV):

“The LORD your God is with you, the Mighty Warrior who saves. He will take great delight in you; in His love He will no longer rebuke you, but will rejoice over you with singing.”

String concatenation combines two or more values into a new string.

The string concatenation operator “+” concatenates the strings together.

String interpolation combines “multiple values into a single literal string by using a “template” and one or more interpolation expressions.

These interpolation expressions are indicated with “{ }”.

The literal string becomes a template when it is prefixed with “$”.

This is the output:

As you can see, #1, is a string cocatenation and the two strings are combined with the “+”.

#2 is a string interpolation which uses a template and “{ }” & “$” signs.

#3 is also a string interpolation, but the template adds in a few extra spaces as underlined in green. The output demonstrates the result of adding these extra spaces in the template.

Finally, you can see that #1 & #2 produce the same output. However, #3 is distinct because of the extra spaces between “World” and “Jesus”.

Zephaniah 3:17 (NIV):

“The LORD your God is with you, the Mighty Warrior who saves. He will take great delight in you; in His love He will no longer rebuke you, but will rejoice over you with singing.”



Comments

One response to “C# – String Concatenation & String Interpolation”

  1. […] Recall that string interpolation can combine multiple values into a single string by utilizing a template & interpolation expressions. […]

Leave a Reply

Your email address will not be published. Required fields are marked *