Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个可以为空的 int。我想将其值设置为,null因此我执行以下操作:
null
int? X; X = 1; X = default(int?);
它保留旧值 of1而不是设置X为null。
1
X
我该如何解决?
不,它不保留值1,变量获取值null:
using System; class Program { static void Main() { int? X; X = 1; X = default(int?); Console.WriteLine(X.HasValue); } }
输出:
False