-
Notifications
You must be signed in to change notification settings - Fork 6k
Add example of concatenated interpolated strings #29785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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 - thank you 🙏
var firstWord = "Hello"; | ||
var secondWord = "World"; | ||
|
||
var combinedInterpolatedString = $"{firstWord}, " + $"{secondWord}!"; |
There was a problem hiding this comment.
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}!";
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
Summary
Adds a description of how to break up interpolated strings, based on feedback in #29440.
Fixes #29440.