thumbmunkeys thumbmunkeys - 4 months ago 35
C# Question

String Format descriptive text

Is it possible to add some descriptive text to a string format specifier?


string.Format ("{0:ForeName} is not at home", person.ForeName);

In the example
is added as description.

The above syntax is obviously incorrect, but just to show the idea.

The reason I am asking, is because in my case the strings are in a resource file, so in the resource file you currently only see

{0} is not at home

in some cases it is hard to grasp what the context of


In c# 6 string interpolation with the
operator has been introduced, so
is not needed anymore:

$"{person.ForeName} is not at home";


We usually put comments into our resources file e.g. {0} = Forename.

Then anybody who might be translating the string knows what {0} represents and can translate accordingly.

Also if you use ReSharper, you can enter the comment at the same time when you are adding your string to resources.