• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 215
  • Last Modified:

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!
0
indy500fan
Asked:
indy500fan
  • 3
  • 2
2 Solutions
 
Jaime OlivaresSoftware 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 OlivaresSoftware ArchitectCommented:
a little typo, missing parenthesis. Should be:

         if (int.TryParse(value, out intRunID))
0
 
p_davisCommented:
or
Convert.ToInt32(value)
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.

 
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

Featured Post

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.

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