C # String.Format () returns bad characters

I get very strange string.Format behavior. I form the message as follows:

protected override string GetMessageText(ManualEventFact reason) { var messageText = string.Format("   {0}(\"{1}\")",reason.EventTemplate.DisplayName, reason.Text); return messageText; } 

The letters begin in Russian. But then, in the call method, I get this line: Äèñïåò÷åð çàêðûë ñîáûòèå (" ") . This is similar to string.Format returns non-Unicode characters for hard-coded words. How can I deal with this problem? Postscript I also came across this in other parts of my application.

+5
source share
1 answer

There is probably a problem in the encoding of the source file ... If you are using Visual Studio, open the cs file and then go to FileSave (your cs) As , then next to the Save button, click the small arrow Save With Encoding , and for Encoding select Unicode (UTF-8 with signature) - Codepage 65001 .

+7
source

All Articles