Boxing and Unboxing in .NET

Boxing and Unboxing in .NET

Boxing and Unboxing in .NET
Ganesh
Wednesday 3 May 2017

BOXING AND UNBOXING -


Boxing

Boxing เคตเคน process เคนोเคคी เคนै เคœिเคธเคฎें value type เค•ो object type เคฏा reference type เคฎें convert เค•िเคฏा เคœाเคคा เคนै।
เค‡เคธ process เค•ो implicit process เคญी เค•เคนเคคे เคนैं।
Example - int i=123;
                   Object(O)=i;
เค‡เคธเคฎें O, i เค•ा เคฐेเคซเคฐेंเคธ เคฆे เคฐเคนा เคนै।




Unboxing -

  Unboxing เคตเคน process เคนै เคœो object เคฏा reference type เคธे value เค•ो value type เคฎें convert เค•เคฐ เคฆेเคคी เคนै।
เค‡เคธ process เค•ो explicit process เคญी เค•เคนเคคे เคนैं।

Example- O=123;
                   i=(int)O;
เค‡เคธ example เคธे object 'O' unbox เคนो เคœाเคฏेเค—ा เค”เคฐ เค‰เคธเค•ी value integer 'i' เคฎें เคšเคฒी เคœाเคฏेเค—ी เคฏा convert เคนो เคœाเคฏेเค—ी।


Example-
class test Boxing
{
Public static void main(string()args)
{
int i=123;
object O=i;
i=456;
system.console.write("the value type value is={0}"i);
system.console.write("the object type value is={0}"O);
console.Readline();
}
}


Output-
the value type value is = 456
the object type value is = 123


Open Comments
Close comment

1 comment