Andrew Bancroft 10/3/2014

Date, Date?, and the ToString Method in VB.Net

Read Original

This article discusses a common pitfall in VB.Net where developers confuse the Date type with the Nullable Date type (Date?). The author describes a frustrating 45-minute debugging session caused by an InvalidCastException when trying to use a format string with ToString() on a Date? object. The key insight is that Date and Date? have different ToString() overloads; only the non-nullable Date type accepts a format string. The solution involves wrapping the Date? instance in a CType conversion to Date before calling ToString() with the desired format. The article is a technical tutorial aimed at VB.Net programmers and is directly related to IT/technology.

Date, Date?, and the ToString Method in VB.Net

Comments

No comments yet

Be the first to share your thoughts!

Browser Extension

Get instant access to AllDevBlogs from your browser

Top of the Week

No top articles yet