How do I convert an int to a string, for example if a variable is declared as an int and it needs to take user input. I need to convert it so that the user can enter a value. Then I need to do some calulations on the value entered by the user. I know you have to user int 32 parse but I don't know how and where to put it
Loading
SolitairePosted Oct 14, 2006, 4:52 PM
Type to convert to
dot
TryParse
(
the string variable
,
out
the variable of the type to convert to
)
;
Example for converting a string named sa to an integer named ia, supposing that the user input is placed in TextBox1:
string sa; int ia;
sa = TextBox1.Text
Int32.TryParse(sa, out ia);
Is that clear enough for you?
Also remember that if you want to process the number mathematically and display the result in another textbox, you need to convert the number back into a string again.
string snum; int inum;
snum = Convert.ToString(inum);
TextBox2.Text = snum
Drew TaylorPosted Oct 13, 2006, 4:21 AM
Thanks for you replies everyone. I know how to convert data types, but I don't know how to use tryparse.
Venkata SirishPosted Oct 12, 2006, 8:39 AM
SolitairePosted Oct 9, 2006, 9:45 PM
string sa; int ia;
Console.Write("Enter a number: ");
sa = Console.ReadLine();
Int32.TryParse(sa, out ia);
mohitchawlaPosted Oct 9, 2006, 9:13 AM
use any of the below mentioned methods:
int a = 10;
Convert.ToString(a);
or
int a = 10;
string str = a.ToString();
saravanan gajendranPosted Oct 9, 2006, 2:01 AM
jc mandapatPosted Oct 8, 2006, 5:40 AM
Drew TaylorPosted Oct 4, 2006, 6:18 AM
It says The type or namespace num Could not be found. What does this mean?
Arturo SalvamantePosted Oct 3, 2006, 3:11 AM
int num = 5;
string str;
str = num.ToString();