Visual studio feeds

All Visual Studio blogs in one place

Subscribe

Enter your email address:

Delivered by FeedBurner

Increase your website traffic with Attracta.com

Google+

Contact

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

Follow us on FB

Search

VB Quark #7 : Optional Parameters and Dates

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)

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