In C#7, (.NET Framework 4.7+), what is the proper way to include a variable in the alignment component for string interpolation?
The following code gives an error "constant value is expected" for the alignment component.
var x = 5;
var test = $"{"blue",x}";
The C# specs for string interpolation alignment element read:
{<interpolatedExpression>[,<alignment>][:<formatString>]}
alignment
The constant expression whose value defines the minimum number of characters in the string representation of the result of the interpolated expression....
Is there a workaround for the "constant expression" limitation of the alignment setting? Could this be performed with other built-in functions?
Also curious as to why it was implemented with this limitation.