.NET DateTime没有预定义的大小

前端之家收集整理的这篇文章主要介绍了.NET DateTime没有预定义的大小前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
由于DateTime是一个结构,其成员似乎分解为简单的数学值,我不确定为什么在它上面使用sizeof()会在问题标题生成消息.

解决方法

因为CLR只能在运行时确定大小…其中一个原因是“填充”(取决于平台)……

For all other types,including structs,the sizeof operator can be
used only in unsafe code blocks. Although you can use the
Marshal.SizeOf method,the value returned by this method is not always
the same as the value returned by sizeof. Marshal.SizeOf returns the
size after the type has been marshaled,whereas sizeof returns the
size as it has been allocated by the common language runtime,
including any padding
.

Ref.

另见How do I check the number of bytes consumed by a structure?

原文链接:https://www.f2er.com/c/110787.html

猜你在找的C&C++相关文章