是否可以CultureInfo
通过文化英文名获得?
想象一下,我们有:丹麦语、英语、西班牙语等等……
谢谢!
var names = CultureInfo.GetCultures(CultureTypes.AllCultures).ToLookup(x => x.EnglishName);
names["English"].FirstOrDefault();
var EnglishCulture = CultureInfo.GetCultures(CultureTypes.AllCultures)
.Where(r => r.EnglishName == "English");
或者如果你需要FirstOrDefault
var EnglishCulture = CultureInfo.GetCultures(CultureTypes.AllCultures)
.FirstOrDefault(r=> r.EnglishName == "English");
没有内置的方法可以通过它的英文名称来获取文化,所以你可以写一个:
public static CultureInfo getCultureByEnglishName(String englishName)
{
// create an array of CultureInfo to hold all the cultures found,
// these include the users local culture, and all the
// cultures installed with the .Net Framework
CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures);
// get culture by it's english name
var culture = cultures.FirstOrDefault(c =>
c.EnglishName.Equals(englishName, StringComparison.InvariantCultureIgnoreCase));
return culture;
}
这是一个演示:http: //ideone.com/KX4U8l