2

I would like to know if there is any difference between the captioned two methods?

string str = "14.75";
Console.WriteLine(Decimal.Parse(str));
Console.WriteLine(Convert.ToDecimal(str));

Can anyone please let me know? Thanks.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Roy
  • 507
  • 10
  • 22
  • http://msdn.microsoft.com/en-us/library/system.convert.todecimal(v=vs.110).aspx Convert has a lot more overloads for taking other types. TryParse is also a great one, since it won't bomb out on you if it fails. – sab669 Oct 29 '13 at 15:23
  • 2
    "Using the ToDecimal(String) method is equivalent to passing value to the Decimal.Parse(String) method." http://msdn.microsoft.com/en-us/library/hf9z3s65.aspx – clcto Oct 29 '13 at 15:24
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Oct 29 '13 at 15:24
  • Straight from MSDN documentation on Convert.ToDecimal(): The return value is the result of invoking the Decimal.Parse method onvalue. – Darek Oct 29 '13 at 15:25

1 Answers1

4

Decimal.Parse only supports parsing string values, whereas Convert takes other types as well, like, object, int, byte, DateTime etc.

Habib
  • 219,104
  • 29
  • 407
  • 436
  • Not only, not only. Another little bit about it: http://stackoverflow.com/questions/15394032/difference-between-casting-and-using-the-convert-to-method/15395832#15395832 – Adriano Repetti Oct 29 '13 at 15:25