Click here to Skip to main content
Click here to Skip to main content
Alternative Tip/Trick

Tagged as

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

Comments and Discussions

 
Questionalways get null Pinmembertaleofsixstrings27-Sep-13 18:38 
AnswerRe: always get null PinprotectorAspDotNetDev28-Sep-13 16:14 
GeneralDon't confuse devs by using "int? ?? -1" instead use some pa... PinmvpKunal_Chowdhury16-May-11 20:10 
GeneralRe: Good advice. The code I presented is little more than a nove... PinprotectorAspDotNetDev16-May-11 20:45 
GeneralThanks for your improvement! I Like your input, and included... PinmemberEduard Keilholz19-Mar-11 6:37 
GeneralRe: Cool. FYI, I shortened the code further (didn't need parens ... PinprotectorAspDotNetDev19-Mar-11 11:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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
Web03 | 2.8.141223.1 | Last Updated 19 Mar 2011
Article Copyright 2011 by AspDotNetDev
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid