# C# Interpolated String Bug?

**URL:** https://talk.remobjects.com/t/c-interpolated-string-bug/22465
**Category:** C#
**Created:** [July 2, 2020, 9:56am UTC](https://talk.remobjects.com/t/c-interpolated-string-bug/22465 "2020-07-02T09:56:30Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![garry.pettet](https://talk.remobjects.com/user_avatar/talk.remobjects.com/garry.pettet/32/12917_2.png) [@garry.pettet](https://talk.remobjects.com/u/garry.pettet)
#### Post date: [July 2, 2020, 9:56am UTC](https://talk.remobjects.com/t/c-interpolated-string-bug/22465/1 "2020-07-02T09:56:30Z")

</div>

Is it a design choice or an oversight that C# is string interpolation is different between the Elements compiler and the Microsoft compiler?

Take this little console app test program:

```csharp
namespace Test
{
    static class Program
    {
        public static Int32 Main(string[] args)
        {

            string offset = "123";
            string name = "name";
            string index = "index";

            Console.WriteLine(
                $"{offset, 10}" +
                $"{name, 10}" +
                $"{index, 10}"
                );
        }
    }
}

```

Compiling this in Fire I get three errors but the app still launches:

 ![Screenshot 2020-07-02 at 10.52.25](https://talk.remobjects.com/uploads/default/original/2X/5/54fe9c651f526c885d42abf7111cbaf4e767c835.png)

The output in the console is wrong / different from the output in Visual Studio 2019.

Fire output:

 ![Screenshot 2020-07-02 at 10.53.14](https://talk.remobjects.com/uploads/default/original/2X/5/543d6fec38ea67f2b088f94ed932ae5590041bd8.png)

Visual Studio output:

 ![Screenshot 2020-07-02 at 10.53.55](https://talk.remobjects.com/uploads/default/original/2X/c/ceebe55d4da6d26f58fdc5e9f33d328eb7e0af9a.png)

As you can see, the Visual Studio compiler correctly puts the string into columns. See [here](https://docs.microsoft.com/en-us/dotnet/standard/base-types/composite-formatting?redirectedfrom=MSDN).

---

<div class="post-metadata">

### Author: ![garry.pettet](https://talk.remobjects.com/user_avatar/talk.remobjects.com/garry.pettet/32/12917_2.png) [@garry.pettet](https://talk.remobjects.com/u/garry.pettet)
#### Post date: [July 2, 2020, 10:05am UTC](https://talk.remobjects.com/t/c-interpolated-string-bug/22465/2 "2020-07-02T10:05:25Z")

</div>

A workaround (not as elegant) is to use `String.Format`:

```auto
Console.WriteLine(String.Format("{0, 10}{1, 10}{2,10}",
       offset, name, index
       ));

```

It’s not as elegant because you end up having to hardcode the column widths everywhere instead of using a constant.

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [July 2, 2020, 12:33pm UTC](https://talk.remobjects.com/t/c-interpolated-string-bug/22465/4 "2020-07-02T12:33:37Z")

</div>

It looks like we do;'t support the formatting options in interpolated strings. First time I see this TBH, but this is not my area. I’ll log a feature request.

---

<div class="post-metadata">

### Author: ![RemObjectsSoftware](https://talk.remobjects.com/user_avatar/talk.remobjects.com/remobjectssoftware/32/15947_2.png) [@RemObjectsSoftware](https://talk.remobjects.com/u/RemObjectsSoftware)
#### Post date: [July 2, 2020, 12:33pm UTC](https://talk.remobjects.com/t/c-interpolated-string-bug/22465/5 "2020-07-02T12:33:40Z")

</div>

Thanks, logged as [bugs://84586](https://www.remobjects.com/portal/bugs/?id=84586)

---

<div class="post-metadata">

### Author: ![garry.pettet](https://talk.remobjects.com/user_avatar/talk.remobjects.com/garry.pettet/32/12917_2.png) [@garry.pettet](https://talk.remobjects.com/u/garry.pettet)
#### Post date: [July 2, 2020, 12:49pm UTC](https://talk.remobjects.com/t/c-interpolated-string-bug/22465/6 "2020-07-02T12:49:33Z")

</div>

Thanks Marc.

---

<div class="post-metadata">

### Author: ![wuping](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/w/5f8ce5/32.png) [@wuping](https://talk.remobjects.com/u/wuping)
#### Post date: [July 2, 2020, 3:16pm UTC](https://talk.remobjects.com/t/c-interpolated-string-bug/22465/7 "2020-07-02T15:16:29Z")

</div>

> [@mh](#):
>
> It looks like we do;'t support the formatting options in interpolated strings. First time I see this TBH, but this is not my area. I’ll log a feature request.

Can Oxygene also benefit from this feature request?

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [July 2, 2020, 3:19pm UTC](https://talk.remobjects.com/t/c-interpolated-string-bug/22465/8 "2020-07-02T15:19:14Z")

</div>

> [@wuping](#):
>
> Can Oxygene also benefit from this feature request?

We’ll have to see if this is syntactically unambiguous (I vaguely recall there being concerns), but if so, then we we can probably enable this fort Oxygene as well, yes. maybe I’m confusing this with float formatting options, which IIRC use “`:`” in C#, and that’d not be valid in Oxygene.

---

<div class="post-metadata">

### Author: ![RemObjectsSoftware](https://talk.remobjects.com/user_avatar/talk.remobjects.com/remobjectssoftware/32/15947_2.png) [@RemObjectsSoftware](https://talk.remobjects.com/u/RemObjectsSoftware)
#### Post date: [April 22, 2021, 8:14pm UTC](https://talk.remobjects.com/t/c-interpolated-string-bug/22465/9 "2021-04-22T20:14:55Z")

</div>

[bugs://84586](https://www.remobjects.com/portal/bugs/?id=84586) got closed with status fixed.

---

<div class="post-metadata">

### Author: ![RemObjectsSoftware](https://talk.remobjects.com/user_avatar/talk.remobjects.com/remobjectssoftware/32/15947_2.png) [@RemObjectsSoftware](https://talk.remobjects.com/u/RemObjectsSoftware)
#### Post date: [June 12, 2021, 2:07pm UTC](https://talk.remobjects.com/t/c-interpolated-string-bug/22465/10 "2021-06-12T14:07:22Z")

</div>

[bugs://E24321](https://www.remobjects.com/portal/bugs/?id=E24321) was closed as fixed.
