How to read all countries using C#

No.of Views2066
Bookmarked0 times
Downloads 
Votes0
By  Prabu   On  11 Jul 2010 01:07:43
Tag : CSharp , General
We can use CultureInfo & RegionInfo class for getting all the countries information. From the CultureInfo class, we can get all the Culture information available in .Net Framework.
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

We can use CultureInfo & RegionInfo class for getting all the countries information. From the CultureInfo class, we can get all the Culture information available in .Net Framework. Then we can use RegionInfo class for reading all the information about the region along with the Country name.

Please use the following code snippet to achieve this.

static void Main(string[] args)
{
    List<string> countriesList = new List<string>();foreach (CultureInfo culture in CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures))
    {if (!string.IsNullOrEmpty(culture.Name))
        {
            RegionInfo ri = new RegionInfo(culture.LCID);if (!countriesList.Contains(ri.EnglishName))
            countriesList.Add(ri.EnglishName);
        }
    }

    countriesList.Sort();foreach (string str in countriesList)
        Console.WriteLine(str);           

    Console.ReadLine();
}

 That's all. i hope this code snippet save your time.

 
Sign Up to vote for this article
 
About Author
 
Prabu
Occupation-Software Engineer
Company-
Member Type-Fresh
Location-India
Joined date-23 Jun 2010
Home Page-
Blog Page-http://prabu-guru.blogspot.com/
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top