3

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
  • 8,829
  • 11
  • 33
  • 63

7 Answers7

12

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

mboldt
  • 1,710
  • 11
  • 15
7

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
  • 15,658
  • 12
  • 57
  • 89
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
  • 66,506
  • 23
  • 132
  • 141
2

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

dsgriffin
  • 64,660
  • 17
  • 133
  • 135
2

Represents a int type that can be assigned null.

Ravindra Bagale
  • 16,715
  • 9
  • 41
  • 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,604
  • 16
  • 64
  • 99
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
  • 8,884
  • 5
  • 28
  • 36