如何将String
转换为CultureInfo
?
Cultureinfo ci;
String dummy = dropdownlist.SelectedValue;
ci = (CultureInfo) dummy; // <- compile time error here
错误:无法将字符串转换为CultureInfo。
答案 0 :(得分:1)
您使用CultureInfo.GetCultureInfo
,例如:
System.Globalization.CultureInfo.GetCultureInfo("en");
答案 1 :(得分:0)
嗯,只是一个简单的创作:
CultureInfo ci = new CultureInfo(dummy);
整个解决方案:
CultureInfo ci = String.IsNullOrEmpty(dropdownlist.SelectedValue)
? CultureInfo.InvariantCulture // Or use other default
: new CultureInfo(dropdownlist.SelectedValue);