Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i m making an application using windows form in c#.

i have to do this

int quan = textbox.Text;


but offcourse this gives error so tell me how a textbox value can be assigned to an int var?
Posted
Comments
Sweety Khan 19-Jun-11 15:32pm    
thanx everyone

You have to use either int.Parse[^] or int.TryParse[^]

int quan = 0;
quan = int.Parse(textbox.Text);
This puts the integer value into "quan" or throws an exception if there are problems with the conversion.
int quan = 0;
if (int.TryParse(textbox.Text, out quan))
   {
   ...
   }
This put the integer value into "quan" and returns true, or returns false if there are problems with the conversion.
 
Share this answer
 
int.Parse or int.TryParse will do the trick!

Cheers!

--MRB
 
Share this answer
 
string a = textbox.text.Tostring();
int ABC = (int) a;
 
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