将字符串转换为cultureinfo

时间:2015-09-22 12:59:19

标签: c# cultureinfo

如何将String转换为CultureInfo

Cultureinfo ci;
String dummy = dropdownlist.SelectedValue; 
ci = (CultureInfo) dummy; // <- compile time error here
  

错误:无法将字符串转换为CultureInfo。

2 个答案:

答案 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);