(2010-08-02) C#.NET Boxing and UnBoxing

摘要:(200-07-30) C#.NET Boxing and UnBoxing

Packing 包裝 ( Value Type )值型別

 

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

namespace mod01
{
    class TestBoxing
    {
        public static void Main()
        {
            //定義整數 to object物件
            Int32 i1= 100;
            Int32 i2 = i1; //i1將內容100複製一份給i2
            Object o1 = i1; //autboxing 將 100封裝成object物件(給位置)
            System.Console.WriteLine(o1.GetType().ToString());
            System.Console.WriteLine(o1.ToString());
            System.Console.WriteLine(Convert.ToInt32(o1) * 100); //unboxing 將物件內 100取出來

        }

    }
}