Click here to Skip to main content
Click here to Skip to main content

Six important .NET concepts: Stack, heap, value types, reference types, boxing, and unboxing

By , 14 May 2012
 
Source_Code.zip
Source Code
WindowsBoxingUnBoxingPerformance
_UpgradeReport_Files
UpgradeReport_Minus.gif
UpgradeReport_Plus.gif
Backup
WindowsBoxingUnBoxingPerformance
Properties
Settings.settings
WindowsBoxingUnBoxingPerformance
bin
Debug
WindowsBoxingUnBoxingPerformance.exe
WindowsBoxingUnBoxingPerformance.vshost.exe
WindowsBoxingUnBoxingPerformance.vshost.exe.manifest
obj
Debug
TempPE
Properties
Settings.settings
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace WindowsBoxingUnBoxingPerformance
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnUnboxandBox_Click(object sender, EventArgs e)
        {
            Stopwatch obj = new Stopwatch();
            obj.Start();
            for (int i=0; i < 10000; i++)
            {
                BoxUnbox();
            }
            obj.Stop();
            lblBoxUnBox.Text = obj.Elapsed.ToString();
            
        }
        private void BoxUnbox()
        {
            int i = 123;
            object j = i;
        }
        private void SimpleVariableAssignment()
        {
            int i = 123;
            int j = i;
        }
        private void btnSimpleVariableAssignment_Click(object sender, EventArgs e)
        {
            Stopwatch obj = new Stopwatch();
            obj.Start();
            for (int i=0; i < 10000; i++)
            {
                SimpleVariableAssignment();
            }
            obj.Stop();
            lblSimple.Text = obj.Elapsed.ToString();
            
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of use and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Shivprasad koirala
Architect http://www.questpond.com
India India
Member

I am a Microsoft MVP for ASP/ASP.NET and currently a CEO of a small
E-learning company in India. We are very much active in making training videos ,
writing books and corporate trainings. Do visit my site for 
.NET, C# , design pattern , WCF , Silverlight
, LINQ , ASP.NET , ADO.NET , Sharepoint , UML , SQL Server  training 
and Interview questions and answers


Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 14 May 2012
Article Copyright 2010 by Shivprasad koirala
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid