Is there a way to concat a string with char as const?

If i try

const char NoChar = (char)8470; //№ const char TmChar = (char)8482; //™ const string IdDisplayName = "Clements" + TmChar + ' ' + NoChar; 

it will throw a compilation error:

The expression assigned to '{0}' must be constant

As far as I understand, this error occurs because when a char happens because the string concatenation operator ( + ) internally calls a ToString on the concatenated object.

My question is, is there a way (unmanaged? Tongue ), to do this.

I need to pass this constant as an attribute, and it needs to be generated on the client.

An in-depth workaround (will see that the uglier one based on your answers ...) is to subclass which attribute (which is sealed, will have to do some decompilation and copy-paste operation) and paste it as non-constant is possible.

+4
source share
2 answers

You can specify Unicode character characters directly in a string using \u escape. Therefore const string IdDisplayName = "Clements\u2122 \u2116"; should get what you want.

+6
source

I assume it is simple:

 const string NoChar = "\x2116"; //№ - Unicode char 8470 const string TmChar = "\x2122"; //™ - Unicode char 8482 const string IdDisplayName = "Clements" + TmChar + " " + NoChar; 

Unacceptably?

+3
source

Source: https://habr.com/ru/post/1398540/


All Articles