Boxing and Unboxing in .NET
page 7 of 8
by Sandeep Acharya
Feedback
Average Rating: 
Views (Total / Last 10 Days): 32923/ 333

Benefits

Both boxing and unboxing are wanted devils. While the boxing process occurs, there is an additional memory loss occurrence. This memory is actually needed for pointer to virtual method and pointer to sync table which is not there in the case of value type objects.

During the unboxing process, however, memory relaxation occurs, but at the same time some unwanted checking (like whether the reference type variable is not Null or it is a valid boxed value or not) takes place.

If we compare Reference type and Value type Objects, then we certainly prefer Value Type objects. This is because as Reference types are coming from the managed heap/memory, they used to affect the Garbage Collection and memory management. On other hand, since Value types run on thread’s stack there is no need to be worried for a garbage collection to occur for them.

So, for these reasons we should avoid unnecessary boxing/unboxing processes and only add them when the application demands it. However, the fact remains that most of the developers are not aware of the underlying complications and they repeat these unnecessary processes unknowingly, which can lead to the degradation of the performance.


View Entire Article

Article Feedback

Title:  
Name:  
Url: ( Optional )
Comment:  
Please add 8 and 2 and type the answer here:

User Comments

Title: hello   
Name: Douglas
Date: 9/28/2009 7:31:56 AM
Comment:
Ceci est le cache Google de http://aspalliance.com/986. Il s'agit d'un instantané de la page telle qu'elle était affichée le 20 sep 2009 21:06:34 GMT. La page actuelle peut avoir changé depuis cette date. En savoir plus

Version en texte seulLes termes de recherche suivants sont mis en surbrillance : ms shalini hotmail com
Home » Boxing and Unboxing in .NET Not Logged In. Login




AspAlliance.com Web


AspAlliance
Register
Edit My Profile
Author List
Write for Us
About AspAlliance
Contact Us
Privacy Policy
Link To Us
Advertise

Subscribe
Free Newsletter
Newsletter Archive
RSS Syndication

.NET Tutorials
Learn .NET
Learn WCF
Learn WPF
Learn ASP.NET
Learn AJAX
Learn Silverlight
Learn Visual Studio
Learn ADO.NET
Learn LINQ
Learn C# (CSharp)
Learn VB.NET
Learn Web Services
Learn Controls
Learn BizTalk
Learn SharePoint
Learn Mobile
Learn SQL
Learn SQL Reporting
Learn Windows Forms
Learn XML
Learn Crystal Reports
Learn FarPoint
Learn DevExpress
Examples
ASP.NET 2.0 Examples

ASP Tutorials
Learn ASP
Learn VBScript
Learn JScript
Learn SQL
Learn XML

Software Resources
Shopping Cart Ecommerce
Charts and Dashboards

Other Resources
Learn Java
Learn Oracle
Opinion / Editorial
Crystal Reports Alliance
WPF Resources
AJAX Resources
Silverlight Resources

Free Tools
Cache Manager
SimpleCMS

Reviews
Book Reviews
Product Reviews
Expert Advice

Books
ASP.NET Developer's Cookbook
Sample Chapters
Book Reviews

Community
Developer Jobs
Resource Directory
ASP Email Lists
ASP.NET Email Lists
Whidbey Email Lists
AspAlliance Groups
SQL Email Lists
XML Email Lists
Regular Expressions
MS Communities
CodeWise Communities

Web Hosting
ASP Hosting
Dedicated Servers
FREE Hosting
Shared Hosting
Web Farm Hosting


Print Add To Favorites Add to Del.icio.us Email To Friend Rate This Article
Boxing and Unboxing in .NET

page 1 of 8
Publish
Title: need more   
Name: nadhiya.s
Date: 8/14/2009 12:04:56 PM
Comment:
nice example.. but i need more example program ya...
thanks
Title: Thanks Shakuntala   
Name: Sandeep Acharya
Date: 8/14/2008 9:42:17 PM
Comment:
Shakuntala,

Thanks for your posting....
But this one seems to be an invalid casting...If it could be a valid conversion then yes it would be an unboxing.
Title: Need clarification on Ex.of Boxing and Unboxing   
Name: Shakuntala
Date: 8/14/2008 3:28:28 AM
Comment:
String is a reference type so
if we declare
string name = "Shalini";
and
int i = Int.Parse(name);(here we are converting refernce type to int type so it is unboxing)
is this correct one??
Title: Boxing and UnBoxing   
Name: Giribabu
Date: 7/11/2008 1:16:55 AM
Comment:
Everyone is using same example, can you tell/ give me real time example's so that anyone can explain to an interviewer who is asking this question. i hope he will not satisfy by simple explaining this concept as it is. I will give you a sample where we use boxing in realtime project, you just explain me about that.

example
---------
Suppose MyTestProject Entity has productID
MyTestProject obj = new MyTestProject();
Session["ProductID"] = obj.productID;

can you explain it?
Title: Boxing & UNBoxing   
Name: prasad
Date: 5/21/2008 5:36:37 AM
Comment:
kinly give me more examples about it and what is the advantages of using boxing&Unboxing.How should explain in the interview.

Note:please write the definition
Title: Boxing & UNBoxing   
Name: venkat
Date: 4/9/2008 4:01:28 AM
Comment:
give me more examples & what is the benifit
send me mail:rams.marni@gmail.com
Title: Boxing & UNBoxing   
Name: Shashi
Date: 3/23/2008 4:36:22 AM
Comment:
give me some more examples,
and tell it benefits,Where we r using..


please give me clear idea about these Article. mail me
(shashimalraj@hotmail.com)
Title: Real Boxing   
Name: Satish Dasari
Date: 3/5/2008 11:52:23 AM
Comment:
Excellent
Title: Clarity on the Basic   
Name: B Srinivasan
Date: 12/27/2007 1:11:15 PM
Comment:
Good description with the sample to explain the Boxing concept. Its worth for the beginner/new to this .NET feature
Title: Boxing & Unboxing   
Name: saleem
Date: 12/20/2007 3:41:19 PM
Comment:
-give me some more examples,
and tell it benefits.
-Why we are using boxing and unboxing. what is the use. where
we are using this concept. can u say.

please give me clear idea about these Article. mail me @ (saleem.mas@gmail.com)
Title: Good Job   
Name: Harry
Date: 12/5/2007 6:58:43 AM
Comment:
Nice example. ;-)
Keep writing.
Title: No clarity   
Name: saki
Date: 11/5/2007 4:16:11 AM
Comment:
just ok
Title: use less article   
Name: sameer
Date: 10/9/2007 8:44:05 AM
Comment:
useless article doenst make sense to me at all
Title: Keep up the good work   
Name: Rajasekhar
Date: 8/22/2007 11:34:44 AM
Comment:
Hai,

This is the correct way to explain any concept. It's really outstanding for us. Please keep writing the articles like this.

Regards - Rajasekhar.
Title: Best explanation online about this subject   
Name: Hung Dao
Date: 7/23/2007 5:53:40 PM
Comment:
I have read several online examples. All simply talks about how boxing and unboxing work but do not really show behind the scene. Keep it up your great work.
Title: nice very good examples are given But   
Name: suyog kale(suyog.kale@gmail.com)
Date: 6/8/2007 5:36:24 AM
Comment:
give me some more examples,
and tell it benefits
Title: Boxing   
Name: shiva
Date: 5/31/2007 3:24:33 AM
Comment:
nice very good examples are given
Title: boxing   
Name: velavan
Date: 4/19/2007 7:03:44 AM
Comment:
very good
Title: About boxing and unboxing   
Name: sathyanarayanan. c
Date: 3/24/2007 7:30:47 PM
Comment:
Why we are using boxing and unboxing. what is the use. where we are using this concept. can u say.
Title: Nice   
Name: Bhupender
Date: 3/22/2007 6:21:45 AM
Comment:
Its Nice, But want some more examples ...
Title: Nice   
Name: Meenu
Date: 2/19/2007 5:44:16 AM
Comment:
Its really nice..Easily understandable..
Well done..
Title: Boxing when calling methods   
Name: ad
Date: 2/9/2007 8:20:36 AM
Comment:
Suppose we have three methods:
- Boxing::CheckBoxingInt(int32)
- Boxing::CheckBoxingObject(object)
- Boxing::CheckBoxingValueType(ValueType)

Boxing (see *) is done when calling CheckBoxingObject() and CheckBoxingValueType(), but not when calling CheckBoxingInt()...

Is this correct, or?

ldarg.0
ldloc.0
call instance void Boxing::CheckBoxingInt(int32)

ldarg.0
ldloc.0
* box [mscorlib]System.Int32
call instance void Boxing::CheckBoxingObject(object)

ldarg.0
ldloc.0
* box [mscorlib]System.Int32
call instance void Boxing::CheckBoxingValueType(class [mscorlib]System.ValueType)
Title: Fine Article   
Name: sonj
Date: 2/8/2007 10:04:03 AM
Comment:
Thanks for directing the Developers
Title: Better method   
Name: prashant kumar singh
Date: 2/4/2007 9:31:19 AM
Comment:
this site is providing better method to uderstanding any topic.
Title: Very Nice   
Name: kiran
Date: 12/22/2006 2:40:58 PM
Comment:
Please try some more......Help
Title: useful article   
Name: keert
Date: 12/15/2006 5:35:52 AM
Comment:
very useful
Title: Good one   
Name: prince
Date: 10/18/2006 7:27:40 PM
Comment:
This information helps me alot,thanks
Title: I Love You Author   
Name: I Love You Author
Date: 10/11/2006 12:45:00 AM
Comment:
I Love You Author.
Title: Thanx   
Name: mansur saeed
Date: 10/10/2006 3:06:41 PM
Comment:
think you very much &carry on
Title: I love it   
Name: .NET Pro
Date: 9/13/2006 9:40:45 PM
Comment:
I love this article, good advice.
Title: Excellent   
Name: Kishor
Date: 9/13/2006 2:26:03 AM
Comment:
Really very usefull article. Keep it up
Title: Nice one   
Name: Sarith koottalakkal
Date: 9/11/2006 10:55:39 PM
Comment:
Keep it up man..
Title: well done   
Name: udit
Date: 9/9/2006 3:43:47 AM
Comment:
the information is given by u regarding boxing & unboxing
it cleare my doubt thanks.keep in touch.
Title: Good Example   
Name: Anoop
Date: 9/9/2006 3:43:17 AM
Comment:
Good Example keep it up
Title: Keep it up   
Name: Manish
Date: 9/8/2006 3:21:08 AM
Comment:
Good, Carry on with ur work
Title: Well Done   
Name: Anita Acharya
Date: 9/7/2006 11:50:20 PM
Comment:
U have chosen a new hobby in ur life.Best of luck & God Bless U.
Title: Keep it up   
Name: prashant
Date: 9/7/2006 9:14:58 AM
Comment:
Good....
Carry on with u r work.

Product Spotlight
Product Spotlight 






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2009 ASPAlliance.com  |  Page Processed at 11/20/2009 11:32:11 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search