2012-10-23 29 views

回答

10

int?意味着它是一个可空的int,所以不仅允许整数值,而且还允许空值。

2

这对Nullable<int>的快捷方式 - 这意味着maxResults可以赋值为null。

+0

我想你的意思是可空,导致存在于nullables – Jehof

+0

我没有任何接口确实:) – lifetimes

7

其aNullable Type,Nullable<T>。按照MSDN

数据类型int基本上是一个值类型,不能保留空值,但通过使用可空类型,你实际上可以存储null。

maxResults = null; // no syntax error 

你可以声明通过使用两个语法Nullable Types

int? maxResults; 

OR

Nullable<int> maxResults; 
2

表示一个int type that can be assigned null.

1

通常,int不能有值,然而使用'?'前缀使得它可以Nullable

int? myNullableInt = null; //Compiles OK 
int myNonNullableInt = null; //Compiler output - Cannot convert null to 'int' because it is a non-nullable value type 
int myNonNullableInt = 0; //Compiles OK 

在你的问题/代码的情况下,我只能认为它是负责的基础上值返回SyndicationFeed结果的maxResults,但其可为空该值可能为空。

1

您不能分配null任何值类型,包括integer。你会得到一个异常

int someValue; 
someValue=null;//wrong and will not work 

但是当你把它空的,你可以指定空。 要设置ValueType为空值,您必须遵循valueetype关键字的标识

<type>? someVariable; 

int? someValue; 
someValue=null;//assigns null and no issues. 

现在你不会得到一个异常,你可以指定null。