如何在c#中将null值设置为int? [英] How to set null value to int in c#?
本文介绍了如何在c#中将null值设置为int?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
int value=0;
if (value == 0)
{
value = null;
}
如何设置值
到 null
以上?
任何帮助都将不胜感激。
Any help will be appreciated.
推荐答案
在.Net中,您不能将 null
值分配给 int
或任何其他结构。相反,请使用 Nullable< int>
或 int?
简称:
In .Net, you cannot assign a null
value to an int
or any other struct. Instead, use a Nullable<int>
, or int?
for short:
int? value = 0;
if (value == 0)
{
value = null;
}
进一步阅读
- Nullable Types (C# Programming Guide)
这篇关于如何在c#中将null值设置为int?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文