Results 1 to 5 of 5

Thread: Question about boxing of variables

  1. #1

    Thread Starter
    Hyperactive Member Utpal's Avatar
    Join Date
    Feb 2002
    Location
    Mumbai, India
    Posts
    393

    Question about boxing of variables

    Hi everybody,
    I am learning VB.NET through a book, which says that assignment of a value type variable to an object variable involves boxing. So, does assignment of an integer variable to a string variable involve boxing?
    It is easy when you know it.

  2. #2
    Lively Member Tygur's Avatar
    Join Date
    Jul 2002
    Posts
    108
    No, it doesn't. When you assign an integer to a string, it gets converted to a string. If Option Strict is on, it won't let you do it without explicitly doing the conversion.

    If you pass an integer into a function that expects an Object, or assign an integer to a variable whose type is Object, then the integer will be boxed.

  3. #3

    Thread Starter
    Hyperactive Member Utpal's Avatar
    Join Date
    Feb 2002
    Location
    Mumbai, India
    Posts
    393
    Thanks ! Isn't a string variable an object variable, because the string type is a class?
    It is easy when you know it.

  4. #4
    Lively Member Tygur's Avatar
    Join Date
    Jul 2002
    Posts
    108
    Originally posted by Utpal
    Thanks ! Isn't a string variable an object variable, because the string type is a class?
    Yes, it is. But the purpose of boxing is so a value type can be passed as an Object, not a String.

  5. #5

    Thread Starter
    Hyperactive Member Utpal's Avatar
    Join Date
    Feb 2002
    Location
    Mumbai, India
    Posts
    393
    Thanks !
    It is easy when you know it.

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