i have tried follow line:
int z = (int) TextBox1.Text);
But this one dosen´t work!
I have use the convert Class:
int z = Convert.ToInt32(textBox1.Text);
It works.
Can you tell me why the first not works?
I have thought thats the same than the second
line?
Cheers
Rene
No, it wouldn't.
> I have use the convert Class:
> int z = Convert.ToInt32(textBox1.Text);
> It works.
>
> Can you tell me why the first not works?
> I have thought thats the same than the second
> line?
No - a cast of object/value X to type Y will only work if:
o The actual type of X is Y or a compatible type
o There is an explict conversion of the *declared* type of X to type Y
o There is an implicit conversion of the *declared* type of X to type Y
--
Jon Skeet - <sk...@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
you cannot explicitly cast objects to value types so conversion routines are
required
There's nothing special about value types here. It's perfectly easy to
write a class for objects which *can* be cast to int:
using System;
public class Test
{
public static explicit operator int(Test t)
{
return 5;
}
public static void Main()
{
int x = (int) new Test();
Console.WriteLine (x);
}
}
The reason the cast fails in the original case is that there is no
conversion operator available for String->int.
--
Check out the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm
"René Paschold" <mai...@rpweb.info> wrote in message
news:b4q7fe$2369k5$1...@ID-96132.news.dfncis.de...
if you want to convert string -> int
intnumber = int.Parse(number);
string -> double
dnumber = double.Parse(number);
anything to string
intnumber.ToString();
dnumber.ToString();
--
Thanks
Ralph Gerbig
mail-to: samu...@web.de
"René Paschold" <mai...@rpweb.info> schrieb im Newsbeitrag
news:b4q7fe$2369k5$1...@ID-96132.news.dfncis.de...