Solved

Converting value from String to Int in a Property

Posted on 2007-11-16
6
190 Views
Last Modified: 2013-12-17
       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
Comment
Question by:indy500fan
  • 3
  • 2
6 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 20300447
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
 
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 500 total points
ID: 20300455
a little typo, missing parenthesis. Should be:

         if (int.TryParse(value, out intRunID))
0
 
LVL 22

Expert Comment

by:p_davis
ID: 20300486
or
Convert.ToInt32(value)
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20300555
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
 

Author Comment

by:indy500fan
ID: 20300728
jaime,

That worked!  Thank you!

Regards,
Eric
0
 

Author Closing Comment

by:indy500fan
ID: 31409615
Excellenet!!!!
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

786 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