How to check if variable integer is empty?

In this class..

Person pr = new Person();

For string I use this
 
 if(!String.IsNullOrEmpty(lastname))

{pr.Lastname = lastname;}

Open in new window


What if it is an integer? for example  variable PersonID. What to use instead of !String.IsNullOrEmpty...
zachvaldezAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
zephyr_hex (Megan)Connect With a Mentor DeveloperCommented:
Correct, you need to use TryParse();

int PersonID;
if (Int32.TryParse(lblPerson.ToString(), out PersonID))
{
	//parse was successful ...PersonID has the integer assigned
}

Open in new window

0
 
p_davisCommented:
unless specifically nullable integers will always have a value.

if it is nullable then you can check the .HasValue property
if it is a db read you can check agains DbNull
1
 
zachvaldezAuthor Commented:
I got this..
int PersonID = Convert.ToInt32(lblPerson.text);
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
p_davisCommented:
i believe if it fails it will return -1 you can use Int32.TryParse with an out value that you can check
0
 
p_davisCommented:
i was wrong about the -1.. you will get an exception. tryparse is your best bet.
0
 
zachvaldezAuthor Commented:
thanks
0
All Courses

From novice to tech pro — start learning today.