How can I create an optional DateTime parameter?

后端 未结 4 1053
悲哀的现实
悲哀的现实 2021-02-18 23:30

I have this function that returns a reference type. Now, this function has two optional parameters both of which are instances of the DateTime class. The function i

4条回答
  •  走了就别回头了
    2021-02-19 00:00

    You can set the DateTime to be nullable and then convert to DateTime.Min if no parameter is provided:

    public DateTime GetDate(DateTime? start = null, DateTime? end = null) {
        var actualStart = start ?? DateTime.Min;
        var actualEnd = end ?? DateTime.Min;
    }
    

提交回复
热议问题