Hi:
I'm new to this, I read thru some example from MSDN:
I'm wondering what does this (int) meant?
Initialized e.Argument as Integer?
"int arg = (int)e.Argument;"
Thanks
Printable View
Hi:
I'm new to this, I read thru some example from MSDN:
I'm wondering what does this (int) meant?
Initialized e.Argument as Integer?
"int arg = (int)e.Argument;"
Thanks
I assume that that is in the DoWork event handler of a BackgroundWorker. The e.Argument property is type Object because you can pass any type of object as the argument. If you want to use it as its actual type then you have to cast it. If you passed an int and you want to use it as an int, e.g. assing it to an int variable, then you have to cast it as type int. That's what that's doing. It's saying that the object referred to by e.Argument is type int and the compiler should treat it as such.
(int)e.Argument
That Meant the (int) in front of e.Argument is actually a cast?
Like the CType in VB.net?
Thanks
Yes, an explicit cast.Quote:
Originally Posted by simon ong
Not quite. It's actually equivalent to DirectCast because CType will perform conversions that an explicit cast will not.Quote:
Originally Posted by simon ong