C#可空类型在实际应用中可以解决一些问题,具体关于它的介绍,可以参考这篇文章,在此感谢作者:
http://blog.csdn.net/ccp5780199/archive/2007/09/01/1768667.aspx
事例代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NullableDemo
{
public class Program
{
/// <summary>
/// 可空类型
/// </summary>
public static void Main(string[] args)
{
// 针对值类型的可空类型
Nullable<DateTime> dt = null;
DateTime? dt2 = null;
// 分配默认值
int? x = null;
int y = x ?? -1;
// x的默认值为0
Console.WriteLine(y.ToString());
Console.ReadLine();
}
}
}