A little tips.
The default value of a function parameter in. NET needs to be a compile-time constant. If the argument is a reference type, you can set NULL, and if it is a value type, you can set the corresponding compile-time constant, such as Integer, but for datetime (struct, value type) How do you want to set the default type?
Typically, the datetime struct is given the default time, that is, DateTime.Now, but DateTime.Now is not compiled at a constant rate and therefore cannot be compiled.
The following code cannot be compiled:
Public Const DateTime defaultdatetime = DateTime.Now;
However, you can do this by setting the DateTime type parameter to be a nullable type, giving its default parameter null, and making a judgment assignment in the function, as follows:
Static void NULL ) { datetime.now;}
The idea is to convert the DateTime parameter to a nullable type, give the default value null, and then in the body of the function, first determine whether the parameter is empty, if it is empty, use DateTime.Now to assign a value, otherwise the parameter value is used.
The above content is very simple, just think this Tips is very fun.
Set default values for. NET datetime type Variables as parameters