C# 10: Constant Interpolated Strings
Constant Interpolated Strings
Yes, it wasn’t possible before but today using C# 10 it is supported. Just imagine what you can do if this feature is available in any programming language.
OK, let’s get started then.
Example
In C# 9.0 or earlier, if you want to merge constant strings, you need to use concatenation, and not interpolation. If you try to use interpolation the compiler won’t be so happy.
Let’s see using C# 9.0, how we concatenate constant string.
Although, another alternative is by removing the const keyword on those variables. Let’s see an example below.
In this section, let’s try to use C# 10’s string interpolation with a constant string. The truth is it helps developers to create more readable constants. You may not agree but that’s how I see it. :-)
That’s pretty much it. Until next time, happy programming!