加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

.NET DateTime没有预定义的大小

发布时间:2020-12-16 03:38:42 所属栏目:百科 来源:网络整理
导读:由于DateTime是一个结构,其成员似乎分解为简单的数学值,我不确定为什么在它上面使用sizeof()会在问题标题中生成消息. 解决方法 因为CLR只能在运行时确定大
由于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?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读