sizeof(int) on x64?

前端 未结 7 1628
眼角桃花
眼角桃花 2020-11-28 13:31

When I do sizeof(int) in my C#.NET project I get a return value of 4. I set the project type to x64, so why does it say 4 instead of 8? Is this because I\'m r

7条回答
  •  北海茫月
    2020-11-28 13:40

    An Int32 is 4 bytes on x86 and x64. An Int64 is 8 bytes either case. The C# int type is just an alias for System.Int32. Same under both runtime environments. The only type that does change depending on the runtime environment is an IntPtr:

        unsafe
        {
            var size = sizeof(IntPtr); // 4 on x86 bit machines. 8 on x64
        }
    

提交回复
热议问题