Skip to content

Conversation

SeanKilleen
Copy link
Contributor

Summary

Adds a description of how to break up interpolated strings, based on feedback in #29440.

Fixes #29440.

Copy link
Member

@IEvangelist IEvangelist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, we'll :shipit: - thank you 🙏

@IEvangelist IEvangelist merged commit 9f475f6 into dotnet:main Jun 10, 2022
var firstWord = "Hello";
var secondWord = "World";

var combinedInterpolatedString = $"{firstWord}, " + $"{secondWord}!";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why wouldn't this just be:

var combinedInterpolatedString = $"{firstWord}, {secondWord}!";

@BillWagner

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would work, but wouldn't show the example as concatenating two interpolated strings. Admittedly, in this case, a single interpolated string would be clear. This would normally be done when all the source expressions were more complex.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gewarren it could be, for sure. I was using an example provided in the initial issue, which discussed concatenating multiple strings together specifically. So it may be that in the context of the example, the usefulness is lost.

Perhaps I could add something like "bear in mind, you could also accomplish this via" and use the syntax you've provided above?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SeanKilleen I'd prefer a more involved example where two different interpolated strings are constructed, then concatenated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Bill here. I don't think this is a good example.


## Combining multiple interpolated strings

To combine multiple interpolated strings, use the interpolation expression for each:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd change this to:

To combine multiple interpolated strings, add the `$` special character to each string literal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Breaking-up interpolated strings into pieces
5 participants