此"int"是什么?方法 ? [英] What does this "int?" means ?

查看:128
本文介绍了此"int"是什么?方法 ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在预先存在的项目(VS2008)中的某个地方(我必须维护的那个地方;-[),我看到一些编码如下:-


Hi,

Somewhere in the pre-existing project(VS2008), (the one that i have to maintain ;-[ ), i see some coding as follows:-


public int? GetInt(object p_objValue)
{
}



在这里,这是什么"int"?是什么意思?

没有错误提到带有"int"的问号.

帮助!!



Here, What does this "int?" means ?

The question mark with "int" is not mentioned by mistake.

HELP !!

推荐答案

在您的情况下,它表示该方法可以返回null作为值.



诠释?表示它是装箱"整数值.那就是一个整数?是可以为空的!
In your case it represents that the method can return null as value.



int? means, it is a "boxed" integer value. That means. a int? is nullable!
int i1=1; //ok
int i2=null; //not ok
int? i3=1; //ok
int? i4=null; //ok




检查此链接
http://social.msdn.microsoft.com/Forums/zh/csharpgeneral/thread/4107d47b-b1c4-495d-a67a-6ad3f2e7adbc [




check this link
http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/4107d47b-b1c4-495d-a67a-6ad3f2e7adbc[^]


int? :允许空值和int值
int:仅允许使用int值


例如:

诠释? i =空; //它起作用了
int i = null; //会报错
int? : allow null value and int value
int : allow only int value


for ex :

int? i = null; // it worked
int i = null; // it gives error


int?i,允许您将空值存储在i或任何其他整数值中

这称为可为空的类型.

进一步了解nullable;

http://www.c-sharpcorner.com/UploadFile/prasoonk/NullableTypeinCSharp06042009092324AM/NullableTypeinCSharp /a> [ ^ ]
int?i, allow you to store null value in i or any other integer value

this is called nullable type.

read more about nullable;

http://www.c-sharpcorner.com/UploadFile/prasoonk/NullableTypeinCSharp06042009092324AM/NullableTypeinCSharp.aspx[^]


这篇关于此"int"是什么?方法 ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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