Solved

What is "int?"  ??

Posted on 2012-03-22
7
351 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:Tom Knowlton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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:Tom 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
Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

 
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:Tom 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:Tom 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 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