G
Guest
Hi,
i read this
http://msdn.microsoft.com/chats/transcripts/vstudio/05_0811_dn_csharp.aspx :
Cyrusn_MS (Expert):
Q: please explain the difference
1: Convert.ToInt32(o)
2: (int)o
3: o as int32
A: Rk: It all depends on what o's type is. Convert.ToInt32 will convert a
lot o standard framework types into an int32. For example, it will allow you
to convert 'true' into '1'. (int)o performs an explicit cast from the o
object to int, and will fail if that type doesn't have such a conversion
(like bool). o as Int32 is not allowed as you cannot have a value type on the
right side of an 'as'. THat's because 'as' returns null if it couldn't
perform the conversion and there is no null Int32 value.
maybe someone can explain this more in detail?
i have an additional point 4: int.Parse() whats about that?
thanks, toebens
i read this
http://msdn.microsoft.com/chats/transcripts/vstudio/05_0811_dn_csharp.aspx :
Cyrusn_MS (Expert):
Q: please explain the difference
1: Convert.ToInt32(o)
2: (int)o
3: o as int32
A: Rk: It all depends on what o's type is. Convert.ToInt32 will convert a
lot o standard framework types into an int32. For example, it will allow you
to convert 'true' into '1'. (int)o performs an explicit cast from the o
object to int, and will fail if that type doesn't have such a conversion
(like bool). o as Int32 is not allowed as you cannot have a value type on the
right side of an 'as'. THat's because 'as' returns null if it couldn't
perform the conversion and there is no null Int32 value.
maybe someone can explain this more in detail?
i have an additional point 4: int.Parse() whats about that?
thanks, toebens