.NET DateTime没有预定义的大小 [英] .NET DateTime Does Not Have a Predefined Size
问题描述
因为CLR只能在运行时确定大小...其中一个原因是padding(依赖平台)...
对于所有其他类型(包括结构体),sizeof运算符只能在不安全的代码块中使用
。虽然可以使用
Marshal.SizeOf方法,但此方法返回的值并不总是与$ size返回值相同的
。 Marshal.SizeOf在类型被封送后返回
大小,而sizeof返回
size ,因为它已由公共语言运行时分配,
包括任何填充。
参考。
另请参阅如何检查我的结构消耗的字节数?
Since DateTime is a struct with members that appear to break down into simple mathematical values, I'm not sure why using sizeof() on it produces the message in the question title.
Because the CLR can only determine the size at runtime... one of the reasons for this is "padding" (platform dependent)...
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.
see also How to check the number of bytes consumed by my Structure?
这篇关于.NET DateTime没有预定义的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!