|
-
Jun 7th, 2003, 12:48 AM
#1
Thread Starter
Hyperactive Member
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.
-
Jun 7th, 2003, 06:56 AM
#2
Lively Member
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.
-
Jun 7th, 2003, 08:16 AM
#3
Thread Starter
Hyperactive Member
Thanks ! Isn't a string variable an object variable, because the string type is a class?
It is easy when you know it.
-
Jun 7th, 2003, 08:32 AM
#4
Lively Member
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.
-
Jun 8th, 2003, 01:42 AM
#5
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|