C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Boxing and UnBoxing


Posted Date: 31 May 2008    Resource Type: Articles    Category: .NET Framework

Posted By: Chandra Sheker.G       Member Level: Gold
Rating:     Points: 2



In .net type system when ever you convert a value type to reference type as shown bellow:

Boxing



The above operation is referred as boxing When ever there is a boxing operations there are 3 costly memory operations occurs

int i = 9;
object o=i;//Boxing



1) A heap memory block is created to store the value of I
2) The value of I will be stored in the heap memory block created
3) The base address of the created heap memory block will be stored in a stack pointer variable called “o”

UnBoxing




When ever a reference type is converted to value type is called UnBoxing
UnBoxing is just like a pointer operation which does not involve in any costly operations as in case of boxing

int i = 9;
object o=i;//Boxing
int k = (int)o;//unboixng
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int i = 9;
object o=i;//Boxing
int k = (int)o;//unboixng

Console.WriteLine("The value of k" + k );//Boxing
Console.WriteLine("The value of i" + i);
Console.Write("The value of k");// the way to privent the aboue boixng
Console.WriteLine(k);
Console.Read();

}
}
}




Responses

Author: Mahesh Raj    07 Jun 2008Member Level: Gold   Points : 1
This is very good information,Continue posting such useful articles.


Author: Roopesh Babu Valluru    25 Jun 2008Member Level: Gold   Points : 0
good article....


Author: Bunty    25 Jun 2008Member Level: Diamond   Points : 2
Hi,

Nice attempt to explain Boxing and Un-boxing in .Net.

In case of boxing the value from value type is copied to the reference type and any modification made on the value type will reflect on the reference type.Because two separate copies are present one in stack and other in heap.

Keep posting such useful article.

Thanks and Regards
S.S.Bajoria


Author: MaNisH GanGraJ    26 Jun 2008Member Level: Bronze   Points : 0
It is good article of Boxing and Unboxing in .Net.


Author: Koshish    01 Aug 2008Member Level: Silver   Points : 1
It is really good article for boxing and unboxing. Can you pls tell me about threading and locking.


Author: Koshish    01 Aug 2008Member Level: Silver   Points : 1
It is really good article for boxing and unboxing. Can you pls tell me about threading and locking.


Author: UltimateRengan    01 Aug 2008Member Level: Diamond   Points : 0
hi,

good information continue for sharing ur knowledge


Author: InterviewsWorld    13 Aug 2008Member Level: Silver   Points : 1
Good information continue for sharing your knowledge.

Thanks,
http://www.interviewsworld.com


Author: Geetha    13 Aug 2008Member Level: Gold   Points : 1
Hi
Good article.
Expecting more knowledge sharing articles from You.
Geetha.


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Difference between ADO and ADO.NET?
Previous Resource: Automating Word to accommodate Spell Check Functionality in your .Net windows application
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

conference call

Contact Us    Privacy Policy    Terms Of Use