重新复习基础草稿:可空类型
原文发布时间为:2008-12-06 —— 来源于本人的百度文章 [由搬家工具导入]
using System;
using System.Collections.Generic;
using System.Text;
namespace fanxing1
{
class Class2
{
static void Main()
{
int? num;//System.Nullable<int> num;
num = null;
if (num.HasValue)
Console.WriteLine(num.Value);
else
Console.WriteLine("null");
num = 4;
int y = num.GetValueOrDefault();
try
{
y = num.Value;
Console.WriteLine(y);
}
catch (System.InvalidOperationException e)
{
Console.WriteLine(e.Message);
}
num = null;
int t = num ?? -1;
Console.WriteLine(t);
int? i = 5;
Type tt = i.GetType();
Console.WriteLine(tt.FullName); //"System.Int32"
Console.WriteLine(typeof(float?));
Console.ReadLine();
}
}
}