-
March 20th, 2007, 11:47 PM
#1
newbie casting question
hi all,
i have what will seem a very basic question to most of you... in vb.net a simple conversion of a number input into a text box is as follows...
Code:
Dim result as Integer
result = cint(txtResult.Text)
i tried to do the same thing in C#...
Code:
int result=0;
result = (int)txtResult.Text;
and it spits out the error "Cannot convert from type string to int" i understand why this occurs, i just dont know how to fix it, or how to go about casting the string result to an integer... can someone please clarfify this question for me?
*sigh* the 'pleasures' of learning a new language :P
cheers
adam
-
March 21st, 2007, 12:05 AM
#2
Re: newbie casting question
result = convert.toint32(txtresult.text)
-
March 21st, 2007, 02:52 AM
#3
Re: newbie casting question
I usually use int.TryParse:
Code:
string s = "1234";
int int32 = 0;
if (!int.TryParse(s, out int32))
{
// Throw MessageBox or likewise here...
}
Sincerely,
Martin Svendsen
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|