Default value for optional parameter of datetime format - VB.NET

N

NWx

Hi,

I want to pass an optional parameter of datetime type to a procedure (in
VB.NET)

But optional parameters require default value.

What value should I use as default for a datetime parameter?

I cannot use "", since it is type string.

Thank you
 
W

William Ryan eMVP

Don't use Optional Parameters would be my advice. Write an overload.
There's a lot of stuff wrong with Optional Parameters....

If you have to use it, come up with some dummy date like 01/01/1900 or some
date that's not valid and use that.

However, I'd really consider writing overloads for it.

HTH,
Bill
 
G

Guest

Ditto on the overloads. If you must, there's also a shared property, DateTime.MinValue, which might be a shade better than making up your own and having to declare the constant. Per the docs: *The value of this constant is equivalent to 00:00:00.0000000, January 1, 0001.* The moral: don't do much math with this one:

----- William Ryan eMVP wrote: ----

Don't use Optional Parameters would be my advice. Write an overload
There's a lot of stuff wrong with Optional Parameters...

If you have to use it, come up with some dummy date like 01/01/1900 or som
date that's not valid and use that

However, I'd really consider writing overloads for it

HTH
Bil
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top