All Visual Studio blogs in one place

AddThis Social Bookmark Button
Hopefully you already know VB has full support for Optional parameters, both declaring them and calling them, but did you know you can use Dates as Optional parameters ?    Public Sub AddNewCustomer(customer As Customer, 
                             Optional dateAdded As Date = Nothing)
      If dateAdded = Nothing Then dateAdded = Now   VB has had this support for Optional parameters in place for the last decade or so in .NET and for years before that back in the COM versions of VB. In the last release of .NET (VS
2010), C# finally got support for Optional parameters, so the above in C# would look like:      public void AddNewCustomer(Customer customer, 
                           DateTime dateAdded = default(DateTime))
         if (dateAdded == default(DateTime)) dateAdded = DateTime.Now;
  The Nothing in the VB declaration is the same as default(DateTime) in C#, which equates to the theoretical Gregorian date of 1/1/0001. But what if you want to specify a default date ? Well because VB...(Read whole news on source site)



Enter your email address:

Delivered by FeedBurner

Increase your website traffic with


Anti-spam: How many eyes has a typical person?

Follow us on FB

Home : Blog List : Bill's random thoughts... : VB Quark #7 : Optional Parameters and Dates