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

前端 未结 7 1789
傲寒
傲寒 2020-12-10 10:18

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

In what scenarios would you use one over the othe

7条回答
  •  失恋的感觉
    2020-12-10 10:45

    Convert.ToDecimal apparently does not always return 0. In my linq statement

    var query = from c in dc.DataContext.vw_WebOrders
    select new CisStoreData()
    {
           Discount = Convert.ToDecimal(c.Discount)
    };
    

    Discount is still null after converting from a Decimal? that is null. However, outside a Linq statement, I do get a 0 for the same conversion. Frustrating and annoying.

提交回复
热议问题