Viewing a cultural spoken language as output in C# console app

Glenn Meadows 0 Reputation points
2023-02-28T02:41:12.6866667+00:00

When using the following C# code in a console app, why do I not see the respective cultural language as output? In this case, en-UK for English spoken in the UK and fr-CA for French spoken in Canada. I would expect currency for the dollar and the pound to be shown as well.

Thread.CurrentThread.CurrentCulture = 
  System.Globalization.CultureInfo.GetCultureInfo("en-UK");
Thread.CurrentThread.CurrentCulture = 
  System.Globalization.CultureInfo.GetCultureInfo("fr-CA");

Developer technologies | C#
{count} votes

1 answer

Sort by: Most helpful
  1. Jack J Jun 25,296 Reputation points
    2023-02-28T05:39:18.78+00:00

    @Glenn Meadows, Welcome to Microsoft Q&A, you could try the following code to get the respective cultural language output.

        internal class Program
        {
            static Random rnd = new Random();
            static void Main(string[] args)
            {
                Console.OutputEncoding= Encoding.UTF8;
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("fr-FR");
                Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("fr-FR");
                DisplayValues();
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("EN-US");
                Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("EN-US");
                DisplayValues();
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("JP-JP");
                Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("JP-JP");
                DisplayValues();
    
            }
            private static void DisplayValues()
            {
    
                Console.WriteLine("Some currency values:");
                for (int ctr = 0; ctr <= 3; ctr++)
                    Console.WriteLine("   {0:C2}", rnd.NextDouble() * 10);
            }
        }
    
    

    Based on my test, the three languages could get different currency formats:

    User's image

    Best Regards,

    Jack


    If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.