Convert.ToDecimal(串)及区别; Decimal.Parse(串) [英] Difference between Convert.ToDecimal(string) & Decimal.Parse(string)

查看:1255
本文介绍了Convert.ToDecimal(串)及区别; Decimal.Parse(串)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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.

这篇关于Convert.ToDecimal(串)及区别; Decimal.Parse(串)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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