Today I got an opportunity to try out the Nullable Types in the .NET Framework 2.0
We had a class inside an application I was working on which basically wrapped a DateTime value called SimpleDate and allowed the developer to treat it like an object.
public class SimpleDate
{
private DateTime simpleDateValue;
public SimpleDate()
{
}
public SimpleDate(DateTime newDate)
{
this.simpleDateValue = newDate;
}
public DateTime Value
{
get
{
return this.simpleDateValue;
}
set
{
this.simpleDateValue = value;
}
}
}
I was able to declare a nullable DateTime like so and replace the above class:
- System.Nullable<DateTime> OR DateTime? in C#
- Nullable(Of DateTime) in VB.NET
If you want to know if is a null or not you use the HasValue method to test your nullable type and you access its value using the Value method.
No comments yet... Be the first to leave a reply!