Why can't I assign null to decimal with ternary operator?

后端 未结 6 848
故里飘歌
故里飘歌 2021-01-17 08:03

I can\'t understand why this won\'t work

decimal? compRetAmount = !string.IsNullOrEmpty(txtLineCompRetAmt.Text) 
    ? decimal.Parse(txtLineCompRetAmt.Text.R         


        
6条回答
  •  别那么骄傲
    2021-01-17 08:38

    Don't use decimal.Parse.

    Convert.ToDecimal will return 0 if it is given a null string. decimal.Parse will throw an ArgumentNullException if the string you want to parse is null.

提交回复
热议问题