You are on page 1of 1

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp12
{
class Program
{
static void Main(string[] args)
{
//nullable definition
DateTime? q = null;

Console.WriteLine(q.GetValueOrDefault());
Console.WriteLine(q.HasValue);

//Console.WriteLine(q.Value);

//casting nullable back and forth


DateTime? d = new DateTime(2002, 8, 14);
DateTime a = d.GetValueOrDefault();
DateTime? b = a;
Console.WriteLine(b.GetValueOrDefault());
Console.ReadLine();

//giving other default values


DateTime? t = null;
DateTime y;

if (t != null)
{
y = t.GetValueOrDefault();
}
else
{
y = DateTime.Today;
}
Console.WriteLine(y);
Console.ReadLine();
}
}
}

You might also like