Wednesday, 1 January 2014

Boxing Example For Beginners In C#

Boxing/Un-Boxing Example For Beginners In C#
 




 private void boxingbtn_Click(object sender, EventArgs e)
        {
            int a = 5;
            object o = a;//boxing
            a = a + a;

            int b;
            b = (int)o;//unboxing
            b = 5 + 5;
            label11.Text = a.ToString();

            label12.Text = b.ToString();

           // boxing
            points p = new points(10,10);
            object box = p;
            p.x = 20;
            label13.Text = ((points)box).x.ToString();

            //Unboxing
            object box1 = 12;
            int x = (int)box1;
            box1 = 12 + 12 + 12;
            label15.Text = x.ToString();

           // Boxing Sample
            int c = 12;
            object d = (object)c;
            label14.Text = d.ToString();

            //Unboxing Sample
            c = (int) d;
            this.Text = c.ToString();


        }

No comments:

Post a Comment