locked
What does 'int?' mean? RRS feed

  • Question

  • Can someone pleaseexplain to me the significance of this declaration?

     

    int? Value;

     

    'int' is obviously a signed 32 bit value but what does the question mark mean?


    Richard Lewis Haggard
    Monday, May 30, 2011 1:14 PM

Answers

  • 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
    
    Monday, May 30, 2011 1:24 PM

All replies

  • It means a nullable type. The value van be null.

    Like:

    int value1 = 0; //you cannot do: int vlaue1 = nulll; - it will be an error
    //if you do:
    int? vlaue2 = null; //will be ok!
    


    Mitja

    Monday, May 30, 2011 1:22 PM
  • It is a short-cut way to write Nullable<int>

    the Nullable<T> struct allows value types to be treated like reference types so that they can hold null values

    http://msdn.microsoft.com/en-us/library/b3h38hb0.aspx#Y114


    Please mark this as answer or vote as helpful if it solved your problem
    Monday, May 30, 2011 1:24 PM
  • 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
    
    Monday, May 30, 2011 1:24 PM
  • Ah! Now that makes sense. It had never occurred to me that this would be shorthand for an int that was enclosed in an object and could thus be either an integer value or a null. Thank you, one and all.
    Richard Lewis Haggard
    Monday, May 30, 2011 2:06 PM
  • hi Richard,

    no, it's not enclosed in an object. It's wrapped in a structure. Read the link provided by GregHenry.


    Microsoft MVP Office Access
    https://mvp.support.microsoft.com/profile/Stefan.Hoffmann
    Monday, May 30, 2011 2:10 PM
  • If you want to declare an integer variable or parameter as null able then you will have to declare as :

    Index(int? id, int? courseID)


    Ahsan Kabir Please remember to click Mark as Answer and Vote as Helpful on posts that help you. This can be beneficial to other community members reading the thread. http://www.aktechforum.blogspot.com/

    Wednesday, October 21, 2015 4:27 AM