Results 1 to 4 of 4

Thread: What is this?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    155

    What is this?

    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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: What is this?

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    155

    Re: What is this?

    (int)e.Argument

    That Meant the (int) in front of e.Argument is actually a cast?

    Like the CType in VB.net?

    Thanks

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: What is this?

    Quote Originally Posted by simon ong
    That Meant the (int) in front of e.Argument is actually a cast?
    Yes, an explicit cast.
    Quote Originally Posted by simon ong
    Like the CType in VB.net?
    Not quite. It's actually equivalent to DirectCast because CType will perform conversions that an explicit cast will not.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width