How can I create an optional DateTime parameter?

后端 未结 4 1063
悲哀的现实
悲哀的现实 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:08

    The only way would be to do it like this (a bit more code, but it gives you optional args):

    public DateTime GetDate(DateTime? start = null, DateTime? end = null)
    {
        // Method body...
        if(start == null)
        {
          start = DateTime.MinValue;
        }
    
        //same for end
    }
    

提交回复
热议问题