I wouldn't expect casting it t work. It isn't and never was an int. It's a
string with that has an integer value. Covert.ToInt32 or Int32.Parse will
work however.
Here's a function you might find handy:
public static int ParseInt(object o, int defaultValue)
{
if (o == null || o == DBNull.Value)
{
return defaultValue;
}
try
{
return Int32.Parse(o.ToString(), CultureInfo.InvariantCulture);
}
catch (Exception ex)
{
if (!(ex is FormatException) && !(ex is InvalidCastException) && !(ex
is OverflowException))
{
throw;
}
return defaultValue;
}
}
Karl
--
http://www.openmymind.net/ http://www.fuelindustries.com/
"Ray Booysen" <rj***********@rjb.za.net> wrote in message
news:ur**************@TK2MSFTNGP05.phx.gbl...
clickon wrote: I have an integer value in a textbox, i want to use the value to perform
a mathematical calculation, however i can only access this value as a
string and i can't cast a string to an int. How do i do this?
(Int32)textbox1.text; for c#
Or even just use the Convert methods.
Convert.ToInt32(textbox1.text)