Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Tagged as

Go to top

Converting a nullable object to an integer

, 19 Mar 2011
As of .NET 2.0, we have a built-in way[^] of converting a Nullable object to an object of type T with a default::int? a;int b = a.GetValueOrDefault(-1);Your example would then be:object someValue = null; // Can be anythingconvertedInteger = ((int?)someValue).GetValueOrDefault(-1);

Revisions


  

Compare Revision Minor Date Status Editor
4 No 19-Mar-11 12:43 Composing Deeksha Shenoy
3 No 19-Mar-11 12:42 Composing Deeksha Shenoy
2 No 19-Mar-11 8:34 Composing Jonathan Cardy
1 No 19-Mar-11 8:31 Composing Jonathan Cardy

License

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

Share

About the Author

Jonathan Cardy
Software Developer Repstor Ltd
United Kingdom United Kingdom
I am a Software Developer at Repstor.

Repstor’s products enable the successful adoption of content management systems within organizations. Repstor affinity provides uninterrupted access to content systems, like SharePoint through the familiar interface of Microsoft Outlook. Repstor assist provides facilitated filing for all users by suggesting the most suitable location for new content based on best practice filing.
Follow on   Twitter

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 19 Mar 2011
Article Copyright 2011 by Jonathan Cardy
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid