为什么字符串转换指定文化 [英] Why specify culture in String conversion

查看:138
本文介绍了为什么字符串转换指定文化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ReSharper的警告我说,我需要指定一个字符串的文化做一个int.ToString时()

Resharper is warning me that I need to specify a string culture when doing an int.ToString()

例如:

int Value = Id.ToString(); // Where Id is an int

有这只是ReSharper的是迂腐的,或者是有原因的,我需要?给一个文化背景为一个int转换为字符串

Is this just resharper being pedantic, or is there a reason I need to give a culture setting for converting an int to a string?

和如果有一个理由这样做 - 什么是最好的使用,当使用我的网站在全球范围内?如果它只是反映服务器的设置,使内部转换是安全的呢?

And if there is a reason to do this - what is the best to use, when my site is used around the globe? Should it just reflect the server settings, so that the internal conversion is done safely?

推荐答案

由于,例如,英语文化的使用。作为小数点,其中法语文化用','和对面来分隔千。指定培养移除此模糊性,使得代码相同执行上配置用于不同的语言,特别是如果所解析的值被提交到持久存储器Windows操作系统。

Because, for example, English cultures use '.' as a decimal point, where as French cultures use ',' and the opposite to separate thousands. Specifying a culture removes this ambiguity so that code executes identically on Windows operating systems configured for different languages, particularly if the parsed values are being committed to persistent storage.

这篇关于为什么字符串转换指定文化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆