Solved

Converting value from String to Int in a Property

Posted on 2007-11-16
6
194 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

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.   …
Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

735 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