[轉]C# 數據類型占轉用的字節數


想知道占用的字節數,干嘛不直接問計算機呢

static void Main(string[] args)
    {
        //int      4 bytes
        Console.WriteLine("int      {0} bytes", sizeof(int));

        //char     2 bytes
        Console.WriteLine("char     {0} bytes", sizeof(char));

        //float    4 bytes
        Console.WriteLine("float    {0} bytes", sizeof(float));

        //double   8 bytes
        Console.WriteLine("double   {0} bytes", sizeof(double));

        //decimal  16 bytes
        Console.WriteLine("decimal  {0} bytes", sizeof(decimal));

        //byte     1 bytes
        Console.WriteLine("byte     {0} bytes", sizeof(byte));

        //short    2 bytes
        Console.WriteLine("short    {0} bytes", sizeof(short));

        //long     8 bytes
        Console.WriteLine("long     {0} bytes", sizeof(long));

        //bool     1 bytes
        Console.WriteLine("bool     {0} bytes", sizeof(bool));
        Console.ReadKey();
    }
View Code

其中bool類型有些疑問。

在MSDN上查看時,其他類型的長度都是有寫出的,就它沒有列出。

http://msdn.microsoft.com/zh-cn/library/vstudio/c8f5xwh7.aspx

其中有什么特別之處嗎?待解


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2026 CODEPRJ.COM