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

后端 未结 6 847
故里飘歌
故里飘歌 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:17

    You need to cast the first part to decimal?

    decimal? compRetAmount = !string.IsNullOrEmpty(txtLineCompRetAmt.Text) 
        ? (decimal?)decimal.Parse(txtLineCompRetAmt.Text.Replace(",","")) 
        : null;
    

提交回复
热议问题