zoukankan      html  css  js  c++  java
  • 代码清单4-2 可空类型的装箱和拆箱行为 代码清单4-3 使用?修饰符来改写代码清单4-2

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Collections;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Nullable<int> nullable = 5;
                object boxed = nullable;
                Console.WriteLine(boxed.GetType());
                int normal = (int)boxed;
                Console.WriteLine(normal);
                nullable = (Nullable<int>)boxed;
                Console.WriteLine(nullable);
                nullable = new Nullable<int>();
                boxed = nullable;
                Console.WriteLine(boxed == null);
                nullable = (Nullable<int>)boxed;
                Console.WriteLine(nullable.HasValue);
                Console.ReadKey();
            }
        }
    }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Collections;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                int? nullable = 5;
                object boxed = nullable;
                Console.WriteLine(boxed.GetType());
                int normal = (int)boxed;
                Console.WriteLine(normal);
                nullable = (int?)boxed;
                Console.WriteLine(nullable);
                nullable = new int?();
                boxed = nullable;
                Console.WriteLine(boxed == null);
                nullable = (int?)boxed;
                Console.WriteLine(nullable.HasValue);
                Console.ReadKey();
            }
        }
    }
  • 相关阅读:
    随机生成30到四则运算题目2 (修改)
    随机生成30到四则运算题目2
    随机生成30道四则运算题目
    第一周学习进度表
    构建之法阅读笔记01
    个人简介
    个人简介
    bat 延时删除指定文件夹中的文件经验分享
    centos 7 (操作应用)-关闭防火墙
    mysql数据库迁移
  • 原文地址:https://www.cnblogs.com/liuslayer/p/6963110.html
Copyright © 2011-2022 走看看