Boxing and unboxing in C#

By: Ram Baskar Emailed: 1646 times Printed: 2115 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

Boxing is the operation of converting a value of a value type into a value of a corresponding reference type. Boxing in C# is implicit.

Unboxing is the operation of converting a value of a reference type (previously boxed) into a value of a value type. Unboxing in C# requires an explicit type cast. A boxed object of type T can only be unboxed to a T (or a nullable T).

Example:
int foo = 42; // Value type.
object bar = foo; // foo is boxed to bar.
int foo2 = (int)bar; // Unboxed back to value type.

Csharp Home | All Csharp Tutorials | Latest Csharp Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(0)


Be the first one to add a comment

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Ram Baskar
Hello World sample program in C#
Comments in C#
Preprocessor directives in C#
Boxing and unboxing in C#
Categories of datatypes in C#
Major features of C#
Which version of C# to use?
History of C#?
Why it was named C#?
Design Goals of C#
What is C#?
A complete sample program in AJAX
Handling the Server Response in AJAX
How to Make an HTTP Request in AJAX

More Tutorials in Csharp
Major features of C#
Categories of datatypes in C#
Boxing and unboxing in C#
Preprocessor directives in C#
Comments in C#
Hello World sample program in C#
SOAP serialization in C#
What is C#?
Design Goals of C#
Why it was named C#?
History of C#?
Which version of C# to use?
Convert Image to Base64 String in C#
Convert Base64 String to Image in C#

More Latest News
Most Viewed Articles (in Csharp )
History of C#?
Major features of C#
Why it was named C#?
Convert Image to Base64 String in C#
Boxing and unboxing in C#
Hello World sample program in C#
Convert Base64 String to Image in C#
What is C#?
Preprocessor directives in C#
SOAP serialization in C#
Design Goals of C#
Which version of C# to use?
Categories of datatypes in C#
Comments in C#
Most Emailed Articles (in Csharp)
SOAP serialization in C#
Design Goals of C#
Convert Image to Base64 String in C#
What is C#?
Why it was named C#?
Categories of datatypes in C#
Convert Base64 String to Image in C#
Which version of C# to use?
Major features of C#
Boxing and unboxing in C#
Comments in C#
Hello World sample program in C#
History of C#?
Preprocessor directives in C#