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?
Printable View
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?
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.
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.Quote:
Originally posted by Utpal
Thanks ! Isn't a string variable an object variable, because the string type is a class?
Thanks !