欢迎访问我的博客 https://javascript.shop

重新复习基础草稿:可空类型

原文发布时间为: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();
        }
    }
}

posted @ 2017-07-11 00:37  孑孓子  阅读(111)  评论(0编辑  收藏  举报
欢迎访问我的博客 https://javascript.shop