Alex Rivera | Logout

Difference between Convert.ToDecimal(string) & Decimal.Parse(string)

Asked 2008-09-18T01:31:07.803
40

What is the difference in C# between Convert.ToDecimal(string) and Decimal.Parse(string)?

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?

Edit
Report

1 Answer

47

From bytes.com:

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.

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

Morten Wennevik [C# MVP]

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.

answered 2008-09-18T01:33:18.063

Your Answer