Convert.ToDecimal(串)及区别; Decimal.Parse(串)区别、ToDecimal、Convert、Decimal

由网友(我服许仙敢日蛇@)分享简介:与在C#中的区别是什么Convert.ToDecimal(字符串)和 Decimal.Parse(字符串)? 在什么情况下你会用一个比其他?In what scenarios would you use one over the other?它会对性能产生什么影响?What impact does it hav...

在C#中的区别是什么Convert.ToDecimal(字符串) Decimal.Parse(字符串)

在什么情况下你会用一个比其他?

In what scenarios would you use one over the other?

它会对性能产生什么影响?

What impact does it have on performance?

在两者之间进行选择时,我应该考虑哪些其他因素?

What other factors should I be taking into consideration when choosing between the two?

推荐答案

从 bytes.com :

Convert类的设计   将各种类型的,所以你   可以将更多类型为十进制比   你可以用Decimal.Parse,从而可以   只处理字符串。在另一   手Decimal.Parse让你   指定NumberStyle。

The Convert class is designed to convert a wide range of Types, so you can convert more types to Decimal than you can with Decimal.Parse, which can only deal with String. On the other hand Decimal.Parse allows you to specify a NumberStyle.

十进制和十进制的别名和   都是平等的。

Decimal and decimal are aliases and are equal.

有关Convert.ToDecimal(串),   Decimal.Parse在内部调用。

For Convert.ToDecimal(string), Decimal.Parse is called internally.

莫滕Wennevik [C#MVP]

Morten Wennevik [C# MVP]

由于Decimal.Parse在内部调用Convert.ToDecimal,如果你的的极端的性能的要求,你可能要坚持到Decimal.Parse,这将节省一叠框架。

Since Decimal.Parse is called internally by Convert.ToDecimal, if you have extreme performance requirements you might want to stick to Decimal.Parse, it will save a stack frame.

阅读全文

相关推荐

最新文章