Click here to Skip to main content
15,947,612 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want solution in c# .net
Problem 1: I want to count the length of a string without using this code: (str.length.tostring();) or without any code. In my concept, first I want to take value from textbox
String str=textbox1.text; then I want to convert it in integer to count the textbox value
Int x=int32.parse(str);
Label1.text=x;
Show code in my way.
Problem 2: I heard that integer returns string, then string returns what? Like when I add two values
Int x=convert.int32(textbox1.text);
Int y=convert.toint32(textbox2.text);
Similarly output should be =convert.int32(textbox3.text);
Output=x+y;
But why I need to convert it in strng=(x+y); though the output will be in integer.
Problem 3: without try catch method I want to show error while adding two numbers that if I put character or string in textbox1 or textbox2 as input, it will show error message that ”put integer”. I want it in if else method.
Every code or solution should be simple as I am beginner. And please give data type conversions when and how I can convert integer to string and vice versa and all conversions short example with explanation.

What I have tried:

i explained above and tried in my own concept.
Posted
Updated 13-Jul-16 20:37pm
Comments
Patrice T 14-Jul-16 1:14am    
Learn C# correctly. follow tutorials, the answers will come as you get understanding of the language.

1 solution

Integers an strings are different beasts.
The length of a string is NOT equal to the integer the string represents. For instance, the string "5" has length 1 while (of course) representing the integer 5. So the String.Length property and the Int32.Parse method serve a different purpose.
Assuming you want to implement a simple (e.g. just an adder) calculator you have to:
  • Convert the string representation of the numbers to the actual integers.
  • Perform the requested (and predefined) operation
  • convert back the result to a string in order to produce the output to the user
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900