7

是否可以CultureInfo通过文化英文名获得?

想象一下,我们有:丹麦语、英语、西班牙语等等……

谢谢!

4

3 回答 3

11
var names = CultureInfo.GetCultures(CultureTypes.AllCultures).ToLookup(x => x.EnglishName);
names["English"].FirstOrDefault();
于 2012-11-12T11:08:59.443 回答
9
var EnglishCulture = CultureInfo.GetCultures(CultureTypes.AllCultures)
                                .Where(r => r.EnglishName == "English");

或者如果你需要FirstOrDefault

var EnglishCulture = CultureInfo.GetCultures(CultureTypes.AllCultures)
                                .FirstOrDefault(r=> r.EnglishName == "English");
于 2012-11-12T11:10:18.583 回答
3

没有内置的方法可以通过它的英文名称来获取文化,所以你可以写一个:

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

于 2012-11-12T11:13:08.420 回答