Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to "try parse" a string to System.Globalization.CultureInfo

Tags:

c#

cultureinfo

In C#, I am using

CultureInfo.GetCultureInfo(myCulture)

but the string variable may not come in a good format, is there a way to try parse the string first or verify it first.

like image 430
Li Tian Gong Avatar asked Sep 10 '12 05:09

Li Tian Gong


1 Answers

The following yields a collection of all cultures:

CultureInfo.GetCultures(CultureTypes.AllCultures)

From there, rather than GetCultureInfo you could do:

.FirstOrDefault(c => c.Name == myCulture)

Rather than AllCultures you may want to filter out SpecificCultures.

like image 163
David Hedlund Avatar answered Oct 25 '22 00:10

David Hedlund