DateTime is a value-type (struct), where-as string is a reference-type (class etc). That is the key difference.
A reference can always be null; a value can't (unless it uses Nullable<T> - i.e. DateTime?), although it can be zero'd (DateTime.MinValue), which is often interpreted as the same thing as null
A reference can always be null; a value can't (unless it uses Nullable<T> - i.e. DateTime?), although it can be zero'd (DateTime.MinValue), which is often interpreted as the same thing as null
C# that causes null DateTime error
using System;
class Program
{
static void Main()
{
DateTime current = null;
}
}
Results
error CS0037: Cannot convert null to 'DateTime'
because it is a non-nullable value type