Solved

What is "int?"  ??

Posted on 2012-03-22
7
347 Views
Last Modified: 2012-03-22
In C#:

 public int? blue_green_apps { get; set; }


why the "?" after the int?

Not familiar with this syntax.
0
Comment
Question by:knowlton
7 Comments
 
LVL 9

Assisted Solution

by:joshbula
joshbula earned 400 total points
ID: 37753142
It just means it's nullable.  It either has value (the value of the int) or can have no value (null).
0
 
LVL 5

Author Comment

by:knowlton
ID: 37753212
How long has this syntax been around?

Is it unique to MVC or is it part of C# everywhere?
0
 
LVL 18

Accepted Solution

by:
Anil Golamari earned 100 total points
ID: 37753273
http://msdn.microsoft.com/en-us/library/b3h38hb0%28v=vs.80%29.aspx

Just more information to Joshbula already mentioned above regarding int?

This syntax is supported right now .Net 2.0 framework.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 9

Expert Comment

by:joshbula
ID: 37753311
I'm not sure how long it's been around, and I'm pretty sure it's part of C# everywhere.  There's even a way to do it in Visual Basic as well, but I think the question mark goes after the variable instead.
0
 
LVL 5

Author Comment

by:knowlton
ID: 37753346
I'm not sure how long it's been around, and I'm pretty sure it's part of C# everywhere.  There's even a way to do it in Visual Basic as well, but I think the question mark goes after the variable instead.

Thanks for the follow-up.

Thank you both for your time!
0
 
LVL 5

Author Comment

by:knowlton
ID: 37753353
Accepted and Assisted solutions are backwards.  Not the points, just the distinction of Accepted vs Assisted.
0
 
LVL 40
ID: 37755657
Yes, you can do it in VB by putting the ? after the name of the variable.

But personnally, I do not like that syntax, either in VB or in C#, because it is simply a shortcut to declaring a variable of the Nullable type:

public Nullable<int> blue_green_apps {get; set;}

The result is the same (int? creates a Nullable<int>), but the "standard" declaration makes it easier for everybody to understand what is happening.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now