Click here to Skip to main content
12,629,684 members (33,196 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

6.8K views
4 bookmarked
Posted

Converting a nullable object to an integer

, 19 Mar 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Here is a slightly shorter version of your first conversion:object someValue = 1;int result = someValue as int? ?? -1;
Here is a slightly shorter version of your first conversion:
object someValue = 1;
int result = someValue as int? ?? -1;

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

AspDotNetDev
Web Developer
United States United States
  • Managing Your JavaScript Library in ASP.NET (if you work with ASP.net and you don't read that, you are dead to me).
  • Graduated summa cum laude with a BS in Computer Science.
  • Wrote some articles and some tips.
  • DDR ("New high score? What does that mean? Did I break it?"), ping pong, and volleyball enthusiast.
  • Software I have donated to (you should too):

You may also be interested in...

Comments and Discussions

 
Questionalways get null Pin
taleofsixstrings27-Sep-13 18:38
membertaleofsixstrings27-Sep-13 18:38 
AnswerRe: always get null Pin
AspDotNetDev28-Sep-13 16:14
protectorAspDotNetDev28-Sep-13 16:14 
GeneralDon't confuse devs by using "int? ?? -1" instead use some pa... Pin
Kunal_Chowdhury16-May-11 20:10
mvpKunal_Chowdhury16-May-11 20:10 
GeneralRe: Good advice. The code I presented is little more than a nove... Pin
AspDotNetDev16-May-11 20:45
protectorAspDotNetDev16-May-11 20:45 
GeneralThanks for your improvement! I Like your input, and included... Pin
Eduard Keilholz19-Mar-11 6:37
memberEduard Keilholz19-Mar-11 6:37 
GeneralRe: Cool. FYI, I shortened the code further (didn't need parens ... Pin
AspDotNetDev19-Mar-11 11:43
protectorAspDotNetDev19-Mar-11 11:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161205.3 | Last Updated 19 Mar 2011
Article Copyright 2011 by AspDotNetDev
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid