•
•
•
•
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
![]() |
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
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.
•
•
Join Date: Oct 2007
Location: Bristol, UK
Posts: 1,123
Reputation:
Rep Power: 3
Solved Threads: 47
Hi there Traicey 
Give this a try:
Or
Hope this helps!

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!
If you got your answer, please mark the thread as Solved. It saves time when people are looking to contribute threads or for answers!
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.
•
•
Join Date: Oct 2007
Location: Bristol, UK
Posts: 1,123
Reputation:
Rep Power: 3
Solved Threads: 47
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C# Marketplace
Similar Threads
- homework help with fstream (C++)
- convert lower case letters to uppercase and vice-versa (C++)
- min value (C++)
- Is casting a static array to (char*) in strcpy() dangerous? (C)
- Playing cards (C++)
- Classes and using Static member functions to subtotal/total (C++)
- float declaration problem (Java)
- Need Help with ArrayList sorting (Java)
- accessing private data members (C++)
Other Threads in the C# Forum
- Previous Thread: how to compute a string in c#???
- Next Thread: Control contextmenustrip display



Linear Mode