Help with textbox for calculator
-
I'm relatively new to C# and have just started playing around with WPF. As a start I decided to make a simple calculator. I added one of the permade textboxes to take input from the user, but you can't perform addition, subbtraction, and so on, oporations on a string, and it won't let me typecast the string to another type like double. How can I change the textbox input to something I can use, or what is there some other object I can use to get the input?
-
I'm relatively new to C# and have just started playing around with WPF. As a start I decided to make a simple calculator. I added one of the permade textboxes to take input from the user, but you can't perform addition, subbtraction, and so on, oporations on a string, and it won't let me typecast the string to another type like double. How can I change the textbox input to something I can use, or what is there some other object I can use to get the input?
You can't cast a string to a number but you can convert it. Any of these will work
string num = "1";
int.Parse(num);
int numOut = 0;
int.TryParse(num, out numOut);Convert.ToInt32(num);
I know the language. I've read a book. - _Madmatt
-
You can't cast a string to a number but you can convert it. Any of these will work
string num = "1";
int.Parse(num);
int numOut = 0;
int.TryParse(num, out numOut);Convert.ToInt32(num);
I know the language. I've read a book. - _Madmatt
-
Even with each of those lines it still tells me it can't convert from string to int. in case its signifigant, I'm using Visual Studio 2008 btw.
You are quite obviously doing something incorrectly, each of those lines is accurate. Post what you are doing? and please don't forget to format it properly, i.e. use pre tags
I know the language. I've read a book. - _Madmatt
-
You are quite obviously doing something incorrectly, each of those lines is accurate. Post what you are doing? and please don't forget to format it properly, i.e. use pre tags
I know the language. I've read a book. - _Madmatt
-
Sorry to take more of your time. I've figured out what I did wrong and have gotten it working now.