Nullables如何能够存储null [英] How are Nullables able to store null

查看:67
本文介绍了Nullables如何能够存储null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Nullables 本身是结构,结构不能包含 Null 。那么我们如何能够将 Null 值分配给 Nullable 类型

解决方案

简而言之:这是CLR内部实施的问题。没有矛盾。为什么它不能包含null。如果您定义了某个结构,并在类型名称后添加?,则会创建新类型,与您的结构不同。这个想法在这里得到了很好的解释:

http://stackoverflow.com/questions/2503811/how-are-nullable-types-implemented-under-the-hood-in-net [ ^ ]。



另请参阅: http: //msdn.microsoft.com/en-us/library/ms228597%28v=vs.110%29.aspx [ ^ ]。



-SA

Nullables are itself a structure and structure cannot contain "Null". So how are we able to assign "Null" values to "Nullable"Types

解决方案

In brief: this is a matter of internal implementation of CLR. There is no a contradiction. Why cannot it contain null. If you define some structure, and add ''?'' after the type name, it creates new type, not the same as your structure. The idea is well explained here:
http://stackoverflow.com/questions/2503811/how-are-nullable-types-implemented-under-the-hood-in-net[^].

See also: http://msdn.microsoft.com/en-us/library/ms228597%28v=vs.110%29.aspx[^].

—SA


这篇关于Nullables如何能够存储null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆