Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using supplemental Unicode characters as char literals in C#

Tags:

c#

unicode

Is there a way to use supplemental Unicode characters (for example '🃜') as char literals in C#? I tried it in VS 2017, with the source file saved as UTF-8 with BOM, UTF-16 LE and BE and I always get the error Too many characters in character literal.

like image 605
Victor Grigoriu Avatar asked Oct 26 '25 15:10

Victor Grigoriu


1 Answers

No, char is one UTF-16 code unit. String is a sequence of UTF-16 code units so if you have a codepoint that UTF-16 encodes as two code units, use a String literal.

"🃜"
like image 86
Tom Blodget Avatar answered Oct 29 '25 04:10

Tom Blodget



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!