Solved

What is "int?"  ??

Posted on 2012-03-22
7
345 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Log4Net custom Appender not being fired. 5 45
Hovering effect 9 29
Get String split 5 33
Close word object 13 21
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 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

20 Experts available now in Live!

Get 1:1 Help Now