Converting value from String to Int in a Property

       public string RunIDProperty
        {
            get
            {
                return this.RunID;
            }
            set
            {
                int intRunID;
                intRunID = (int) value;  <--This is where I am trying to convert types, but is says I can't implicitly convert type 'string' to 'int'      

                if (value != "" && (intRunID >= 0 && intRunID <= 50))
                {
                    this.RunID = value;
                }
            }
        }

Thanks in advance!
indy500fanAsked:
Who is Participating?
 
Jaime OlivaresConnect With a Mentor Software ArchitectCommented:
try with this:

    set
    {
         int intRunID;
         if (int.TryParse(value, out intRunID)
         {
                if (intRunID >= 0 && intRunID <= 50)
                       this.RunID = intRunID;
         }
    } 

Open in new window

0
 
Jaime OlivaresConnect With a Mentor Software ArchitectCommented:
a little typo, missing parenthesis. Should be:

         if (int.TryParse(value, out intRunID))
0
 
p_davisCommented:
or
Convert.ToInt32(value)
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Jaime OlivaresSoftware ArchitectCommented:
Convert.ToInt32() will generate an exception if string is not a perfect number.
That's why I don't use int.Parse() instead of int.TyryParse()
0
 
indy500fanAuthor Commented:
jaime,

That worked!  Thank you!

Regards,
Eric
0
 
indy500fanAuthor Commented:
Excellenet!!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.