String Interpolation
Adam Wilson
flyboynw at gmail.com
Wed Oct 25 00:56:34 UTC 2023
On Monday, 23 October 2023 at 14:44:49 UTC, matheus wrote:
> On Monday, 23 October 2023 at 14:12:25 UTC, Rumbu wrote:
>> On Saturday, 21 October 2023 at 18:59:13 UTC, Adam D Ruppe
>> wrote:
>>> On Saturday, 21 October 2023 at 18:31:10 UTC, Imperatorn
>>> wrote:
>>>> In C# an interpolated string is just a string
>>>
>>> This isn't true. It is an object that can convert to string
>>> (similar to D's `alias toString this;`)
>>
>> In fact neither, it's syntactic sugar.
>>
>> ```csharp
>> int count = 10;
>> string s = $"I drink {count} beers";
>> ```
>>
>> is syntactic sugar for:
>> ...
>
> Maybe we're talking about the same thing or it changed, but I
> thought it was a syntactic sugar for string.format():
>
> https://web.archive.org/web/20160304034509/https://roslyn.codeplex.com/discussions/570614
>
> Matheus.
The above is correct for what Roslyn does. The String.Format
stuff comes in when you are trying to format the incoming
variable, like so:
```csharp
string s = $"I drink {count:0000} beers";
```
Which will produce: "I drink 0010 beers"
More information about the Digitalmars-d
mailing list