using System;namespace GetUsernameExample{ class Program { static void Main(string[] args) { string username = Environment.UserName; //нпп Console.WriteLine("Hello, " + username); } }}
In this sample code, I want to get username which is non ascii string but I am getting output as "???"
I tried Console.OutputEncoding = Encoding.UTF8;
and enabling "Beta: Use Unicode UTF-8 for worldwide language support"; then I get the correct non ascii output but I don't want to do the above (as I want to try out in application code not from console app, how can I encode in utf-8 and get the non ascii output).