Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 74
  • Last Modified:

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...
0
zachvaldez
Asked:
zachvaldez
  • 3
  • 2
1 Solution
 
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
 
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
p_davisCommented:
i was wrong about the -1.. you will get an exception. tryparse is your best bet.
0
 
zephyr_hex (Megan)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
 
zachvaldezAuthor Commented:
thanks
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now