从英文名称列表中获取 TwoLetterISOLanguageName 列表
Get list ofTwoLetterISOLanguageName from list of EnglishName
我有一个英文形式的语言列表:
German
English
French
...
我想得到:
DE
EN
FR
我该怎么做?
听起来你只需要获取中性(仅语言)文化的完整列表,将其与你的英文名称列表结合起来,然后投影:
var languageCultures = CultureInfo.GetCultures(CultureTypes.NeutralCultures);
var twoLetterNames = from culture in languageCultures
join englishName in englishNames
on culture.EnglishName equals englishName
select culture.TwoLetterISOLanguageName;
如果您经常这样做,您可能想要构建一个 Dictionary<string, string>
:
var cultureByLanguage = languageCultures.ToDictionary(x => x.EnglishName);
或:
var twoLetterIsoByLanguage = languageCultures.ToDictionary
(x => x.EnglishName,
x => TwoLetterISOLanguageName);
我有一个英文形式的语言列表:
German
English
French
...
我想得到:
DE
EN
FR
我该怎么做?
听起来你只需要获取中性(仅语言)文化的完整列表,将其与你的英文名称列表结合起来,然后投影:
var languageCultures = CultureInfo.GetCultures(CultureTypes.NeutralCultures);
var twoLetterNames = from culture in languageCultures
join englishName in englishNames
on culture.EnglishName equals englishName
select culture.TwoLetterISOLanguageName;
如果您经常这样做,您可能想要构建一个 Dictionary<string, string>
:
var cultureByLanguage = languageCultures.ToDictionary(x => x.EnglishName);
或:
var twoLetterIsoByLanguage = languageCultures.ToDictionary
(x => x.EnglishName,
x => TwoLetterISOLanguageName);