加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – CA1305:int.Parse(String)

发布时间:2020-12-16 07:26:08 所属栏目:asp.Net 来源:网络整理
导读:我收到了CA1305警告. Microsoft.Globalization : Because the behavior of ‘int.Parse(string)’ could vary based on the current user’s locale settings, replace this call in ‘_Default.CalculateImageButton_Click(object, ImageClickEventArgs)’
我收到了CA1305警告.

Microsoft.Globalization : Because the
behavior of ‘int.Parse(string)’ could vary based on the
current user’s locale settings,
replace this call in
‘_Default.CalculateImageButton_Click(object,
ImageClickEventArgs)’ with a call to
‘int.Parse(string,
IFormatProvider)’. If the result of
‘int.Parse(string,
IFormatProvider)’ will be displayed to
the user,specify
‘CultureInfo.CurrentCulture’ as the
‘IFormatProvider’ parameter.
Otherwise,if the result will be
stored and accessed by software,such
as when it is persisted to disk or to
a database,specify
‘CultureInfo.InvariantCulture’.

如果在解析Int32时省略指定文化,究竟会出现什么问题?

解决方法

这意味着当您从数据文件或数据库记录中读取“1,234”时,然后尝试通过Parse将其转换为Int,您将在美国获得1234,在德国获得1.警告提供了很好的建议 – 如果您正在与用户交互,请指定CurrentCulture(感谢Andrew!),如果您正在与文件系统或数据库(或任何!用户)进行交互,请使用InvariantCulture

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读