Solved

How to check if int is null in c#?

Posted on 2014-10-08
4
1,365 Views
Last Modified: 2014-10-09
How to check if int is null in c#?
0
Comment
Question by:developer2012
4 Comments
 

Author Comment

by:developer2012
Comment Utility
How to check if int is null in c#?
0
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 250 total points
Comment Utility
if your variable is declare as int?, you can use YourVariableName.HasValue
0
 
LVL 13

Assisted Solution

by:frankhelk
frankhelk earned 250 total points
Comment Utility
Hmmm - as far as I know, any integral data type like int, float, double, etc. is not really an object, even while it could be treated as one with some weird cast (even while I don't know why one would like to do that besides of curiosity).

Therefore an int variable can have a value of 0, but could not be null (in the meaning of an unitialized object pointer). When it is created, it is initialized to a value of 0 by the compiler, but good practice would be to initialize it prior to usage of the value.

Under that aspects, checking an int variable for 0 is common practice, but checking it for null is quite senseless.

@Éric Moreau:
int? is a special type that explicity allows null as value. See here for explanation of that specialty. The type int itself definitely doesn't allow null.
0
 
LVL 2

Expert Comment

by:Pratik Makwana
Comment Utility
I think you are looking for this.....

if(variable == null)
    Printf .....
else
    Printf.......
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

763 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

8 Experts available now in Live!

Get 1:1 Help Now