User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C# section within the Software Development category of DaniWeb, a massive community of 397,627 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,351 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C# advertiser:
Views: 675 | Replies: 5 | Solved
Reply
Join Date: Mar 2008
Posts: 180
Reputation: Traicey is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 16
Traicey's Avatar
Traicey Traicey is offline Offline
Junior Poster

Static Cast

  #1  
May 14th, 2008
I have 2 integers x and y, now I want to read them from the user and the syntax kick me down, I guess u can only read string from the user according to C# syntax rule, I have tried many combinations but none of them are working, so now I want to know how to static cast string to integer coz I have declared those integers as strings and I have to make some calculations which I cant with strings

Lastly I came up with something like string x, y so I wana type cast them to integers so that I can be able to make those calculation..... any help would be highly appreciated.

Note: Im a novice to C#, and am trying to learn it on my own.... And please dont refer me to some other threads or sites, only one line of code would be sufficient
Last edited by Traicey : May 14th, 2008 at 8:20 am.
Some people get so rich they lose all respect for humanity. That's how rich I want to be.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Location: Bristol, UK
Posts: 1,123
Reputation: majestic0110 is on a distinguished road 
Rep Power: 3
Solved Threads: 47
majestic0110's Avatar
majestic0110 majestic0110 is offline Offline
Veteran Poster

Re: Static Cast

  #2  
May 14th, 2008
Hi there Traicey

Give this a try:

string x = "";    
int parsex = Int32.Parse(x); 


Or

string x = "";
int ConvertedIx = Convert.ToInt32(x);

Hope this helps!
Last edited by majestic0110 : May 14th, 2008 at 9:02 am.
If you have a quality, be proud of it and let it define you. Add it to the world!
If you got your answer, please mark the thread as Solved. It saves time when people are looking to contribute threads or for answers!
Reply With Quote  
Join Date: Mar 2008
Posts: 180
Reputation: Traicey is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 16
Traicey's Avatar
Traicey Traicey is offline Offline
Junior Poster

Re: Static Cast

  #3  
May 14th, 2008
I have something like this string x = Console.ReadLine(); and again I have tried int j = int32.Parse(x) and now I have this code int j = Convert.ToInt32(x) so now the problem is when Im trying to execute this statement result = x - y; I got this error '-' cannot be applied to operand of type string and string, And believe me I dont know why its not working really, seems as if it is ignoring all the conversion and focus on the declaration..... 1st I tried to declare my variables as integers and they told me I cant read integer from the user and now I try to type cast it but hey
Some people get so rich they lose all respect for humanity. That's how rich I want to be.
Reply With Quote  
Join Date: Oct 2007
Location: Bristol, UK
Posts: 1,123
Reputation: majestic0110 is on a distinguished road 
Rep Power: 3
Solved Threads: 47
majestic0110's Avatar
majestic0110 majestic0110 is offline Offline
Veteran Poster

Re: Static Cast

  #4  
May 14th, 2008
Where have you cast the variable Y?
If you have a quality, be proud of it and let it define you. Add it to the world!
If you got your answer, please mark the thread as Solved. It saves time when people are looking to contribute threads or for answers!
Reply With Quote  
Join Date: Mar 2008
Posts: 180
Reputation: Traicey is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 16
Traicey's Avatar
Traicey Traicey is offline Offline
Junior Poster

Re: Static Cast

  #5  
May 15th, 2008
Hey.... I got it right man, I was just being stubborn, adopting donkey mentality, I guess I was too tired, Thanx a lot hey
Some people get so rich they lose all respect for humanity. That's how rich I want to be.
Reply With Quote  
Join Date: Oct 2007
Location: Bristol, UK
Posts: 1,123
Reputation: majestic0110 is on a distinguished road 
Rep Power: 3
Solved Threads: 47
majestic0110's Avatar
majestic0110 majestic0110 is offline Offline
Veteran Poster

Re: Static Cast

  #6  
May 15th, 2008
you are welcome.
If you have a quality, be proud of it and let it define you. Add it to the world!
If you got your answer, please mark the thread as Solved. It saves time when people are looking to contribute threads or for answers!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C# Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C# Forum

All times are GMT -4. The time now is 9:11 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC