What is autoboxing in C# ?
What is autoboxing in C# ?
Collapse
X
-
Amar KapasiTags: None -
If I recall correctly, Autoboxing is a Java concept. Normal "boxing" was primitive types being converted to their respective object types. E.g:
[code=java]
int prim = 123;
Integer obj = (Integer)prim;
[/code]
Autoboxing was introduced later to automate that, removing the need to manually "box" primitives. It would just happen automatically when and as needed.
As far as I know, C# doesn't need this as primitives are basically just aliases for the object types to begin with.
Unless you are talking about "boxing" as in turning things into Object instances, to be stored in hash tables and such. E.g:
[code=cs]
Int32 d = 123;
Object p = (Object)d;
[/code]
P.S.
Been a while since I really used either Java or C# so I might be a bit rusty xD -
I feel like we're answering a homework question here, Atli. But what the hell.
Boxing and Unboxing in C#
For the record, I've never heard of "autoboxing ." I looked it up:
It's pretty much what you said. And you're right, C# doesn't require that, since the primitives are objects that can be referenced. They are aliases to their object types.Comment
-
Yuvraj S Jain
Autoboxing is required in C# as the fundamently the concepts is briefly explained by you but the main thing to use the auto boxing is GC(Garbage Collection) as autoboxing will allows the value type to be stored on the garbage collected heap so that the system runs its own GC at that time no more memory will be there at head area...Comment
Comment