Click here to Skip to main content
12,295,252 members (59,152 online)
Click here to Skip to main content

Stats

1.3M views
2.4K downloads
587 bookmarked
Posted

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

, 14 May 2012 CPOL
An introduction to stack, heap, value types, reference types, boxing, and unboxing.
Source Code
WindowsBoxingUnBoxingPerformance
_UpgradeReport_Files
UpgradeReport_Minus.gif
UpgradeReport_Plus.gif
WindowsBoxingUnBoxingPerformance
Properties
obj
Debug
TempPE
bin
Debug
WindowsBoxingUnBoxingPerformance.exe
WindowsBoxingUnBoxingPerformance.vshost.exe
WindowsBoxingUnBoxingPerformance.vshost.exe.manifest
Backup
WindowsBoxingUnBoxingPerformance
Properties
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 Service 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)

Share

About the Author


You may also be interested in...

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