Possible Duplicate:
C# - Basic question: What is ‘?’?
I have found this statement in a function arguments.
public static SyndicationFeed GetDataFeed(...... int? maxResults)
what does that means?
Possible Duplicate:
C# - Basic question: What is ‘?’?
I have found this statement in a function arguments.
public static SyndicationFeed GetDataFeed(...... int? maxResults)
what does that means?
int? means it's a nullable int, so not only integer values are allowed but also the null-value.
Its a Nullable Type, Nullable<T>
. As per MSDN
DataType int
is basically a value type and cannot hold null value, but by using Nullable Type you can actually store null in it.
maxResults = null; // no syntax error
You can declare the Nullable Types
by using two syntax:
int? maxResults;
OR
Nullable<int> maxResults;
?
means nullable. It means the type can contain a value or be null.
int? num = null; // assign null to the variable num
http://msdn.microsoft.com/en-us/library/1t3y8s4s(v=vs.100).aspx
It's a shortcut for Nullable<int>
- This means that maxResults
can be assigned null.
Typically an int cannot have a null value, however using the '?' prefix allows it to be 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
In the context of your question/code I can only assume that it is responsible for returning SyndicationFeed results based on the value of ?maxResults, however as its nullable this value could be null.
You cannot assign null
to any value type,that includes integer
.You will get an exception
int someValue;
someValue=null;//wrong and will not work
But when you make it nullable,you can assign null. To make a ValueType Nullable,you will have to follow your valuetype keyword with the symbol ?
<type>? someVariable;
int? someValue;
someValue=null;//assigns null and no issues.
Now you wont get an exception and you can assign null.