Search This Blog

Tuesday, June 12, 2012

C# Nullable DateTime

C# > System Namespace > DateTime > Nullable DateTime

// Error Cannot convert null to 'System.DateTime' because it is a non-nullable value type 
   
DateTime AgendaValidFrom;
AgendaValidFrom = null;

Solution:
Add ? to DateTime

DateTime? AgendaValidFrom = null; // Declare a nullable DateTime instance and assign to null.