开发者

Difference between Convert.ToString Method and Object.ToString() with regard to Globalization

Is there any difference between Convert.ToString M开发者_StackOverflowethod and Object.ToString() in C#.net other than how these handle null value. There could be some difference between the two in Globalization Perspective.


Yes and no.

For example, the Convert.ToString(int) method, is identical to the Int32.ToString() method, as MSDN states in the 'Remarks' section: "This implementation is identical to Int32.ToString()." However, the Convert class also offers overrides which take an IFormatProvider as a second parameter (e.g. Convert.ToString(int, IFormatProvider)), and this can be used to adjust the output format, e.g. by passing a CultureInfo instance.


Convert.ToString for the most part calls ToString on the value that is passed in. There are only a few exception for example

Convert.ToString(object, IFormatProvider) which checks if the value implements IConvertable and delegates to that otherwise if the value is not null delegates to value.ToString.

Convert.ToString(IntXX, Int32) where XX is 16, 32, 64. This does a base conversion.

So I do not believe that there is any difference interms of globalization between the two.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜