对我来说,在Convert类中使用以下重载是有意义的
public static double ToDouble(string value, IFormatProvider provider);示例:
Console.WriteLine(Convert.ToDouble("3223.2", CultureInfo.InvariantCulture)); // success
Console.WriteLine(Convert.ToDouble("3223,2", new CultureInfo("fr-FR"))); // success
Console.WriteLine(Convert.ToDouble("3223.2", new CultureInfo("fr-FR"))); // failure但是使用下面的重载的例子是什么呢?
public static int ToInt32(string value, IFormatProvider provider);以下所有操作均失败:
Console.WriteLine(Convert.ToInt32("3223.2", CultureInfo.InvariantCulture));
Console.WriteLine(Convert.ToInt32("3223,2", new CultureInfo("fr-FR")));
Console.WriteLine(Convert.ToInt32("3223.2", new CultureInfo("fr-FR")));换句话说,有没有任何有效的整型字符串表示(在任何区域性中),如果不指定IFormatProvider就不能转换为整型?
https://stackoverflow.com/questions/41241619
复制相似问题