How to initialize var?

前端 未结 11 1888
庸人自扰
庸人自扰 2020-11-27 15:29

Can I initialize var with null or some empty value?

11条回答
  •  無奈伤痛
    2020-11-27 16:02

    Thank you Mr.Snake, Found this helpfull for another trick i was looking for :) (Not enough rep to comment)

    Shorthand assignment of nullable types. Like this:

    var someDate = !Convert.IsDBNull(dataRow["SomeDate"])
                        ? Convert.ToDateTime(dataRow["SomeDate"])
                        : (DateTime?) null;
    

提交回复
热议问题