想知道占用的字节数,干嘛不直接问计算机呢

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

相关文章:

  • 2021-11-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-18
猜你喜欢
  • 2021-12-31
  • 2022-12-23
  • 2021-12-29
  • 2021-06-08
相关资源
相似解决方案