4

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?

Community
  • 1
  • 1
GajendraSinghParihar
  • 9,051
  • 11
  • 36
  • 64

7 Answers7

13

int? means it's a nullable int, so not only integer values are allowed but also the null-value.

mboldt
  • 1,780
  • 11
  • 15
8

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;
Furqan Safdar
  • 16,260
  • 13
  • 59
  • 93
2

? 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

Darren
  • 68,902
  • 24
  • 138
  • 144
2

It's a shortcut for Nullable<int> - This means that maxResults can be assigned null.

dsgriffin
  • 66,495
  • 17
  • 137
  • 137
2

Represents a int type that can be assigned null.

Ravindra Bagale
  • 17,226
  • 9
  • 43
  • 70
1

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.

Jamie Keeling
  • 9,806
  • 17
  • 65
  • 102
1

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.

Prabhu Murthy
  • 9,031
  • 5
  • 29
  • 36