Solved

Converting value from String to Int in a Property

Posted on 2007-11-16
6
195 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

731 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