C# Program to Demonstrate Culture Names

This is a C# Program to demonstrate culture names.

Problem Description

This C# Program Demonstrates Culture Names.

Problem Solution

Here the CultureInfo object that is returned by this property and its associated objects determine the default format for dates, times, numbers, currency values, the sorting order of text, casing conventions, and string comparisons.

Program/Source Code

Here is source code of the C# Program to Demonstrate Culture Names. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

/*
 * C# Program to Demonstrate Culture Names
 */
using System;
using System.Globalization;
using System.Threading;
public class Info : MarshalByRefObject
{
    public void ShowCurrentCulture()
    {
        Console.WriteLine("Culture of {0} in application domain {1}: {2}",
                Thread.CurrentThread.Name,AppDomain.CurrentDomain.FriendlyName,
                CultureInfo.CurrentCulture.Name);
    }
}
public class Example
{
    public static void Main()
    {
       Info inf = new Info();
       Thread.CurrentThread.Name = "MainThread";
       Thread.CurrentThread.CurrentCulture=CultureInfo.CreateSpecificCulture("nl-NL");
       inf.ShowCurrentCulture();
       AppDomain ad = AppDomain.CreateDomain("Domain2");
       Info inf2 = (Info)ad.CreateInstanceAndUnwrap(typeof(Info).Assembly.FullName, 
                    "Info");
       inf2.ShowCurrentCulture();
       Console.ReadLine();
    }
}
Program Explanation

This C# program is used to demonstrate culture names. The culture name is used to represent information about a specific culture including the names of the culture, the writing system, and the calendar used, as well as access to culture-specific objects that provide information for common operations, such as formatting dates and sorting strings.

advertisement
advertisement

Assign the CurrentThread.Name value as a MainThread. The Current Culture is used to create a CultureInfo that represents the specific culture that is associated with the specified name. Then CreateInstanceAndWrap() function is used to create a new instance of the specified type.

Parameters specify the assembly where the type is defined, and the name of the type. Then the Assembly.fullName is used to get the display name of the assembly. Then ShowCurrentCulture() function is used to display the name in the assembly.

Runtime Test Cases
 
Culture of MainThread in application domain ConsoleApplication32.vshoot.exe : nl-NL 
Culture of MainThread in application domain Domain2 : nl-NL

Sanfoundry Global Education & Learning Series – 1000 C# Programs.

Note: Join free Sanfoundry classes at Telegram or Youtube
If you wish to look at all C# Programming examples, go to 1000 C# Programs.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.