






















Consider this following code in C# 2.0
in fact it was complied like this:
please note line 3, when we increased the nullable i, it actually created a new instance of Nullable<int>
new Nullable<int>(nullable3.GetValueOrDefault() + 1)
and in line 6, when we assign null to a nullable instance, it also created a new instance with null value.
nullable2 = new Nullable<int>();
Once we created an instance of Nullable<T>, we can NOT modify the inner value any more. When we modify these value, we actually create a new instance with the new value. Nullable<T> is an immutable type.
It looks like string, right? (though Nullable<T> is a value type)
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。