Sunday 5, 9:30 am I was invited to a WebCast on how to modeling and secure services, where explained step by step ,deliver the PPT, a greeting Carlos Chavez. Lima Peru

One of the consultations that everybody always ask me is about to demonstrate what is normally mentioned about Collections and generics and the CAST, but not only to mention it, but to demonstrate it with an example, because I remembered I saw an example some time ago in a friend’s blog (Iván Mostacero) from Trujillo – Perú. He posted an article that I liked very much. It was about how to explain the difference between generic classes and collections. I liked it so much that I told him I wanted to post it for you guys and answer your questions.
The practical case consists of trying to demonstrate the power of working with Generics in big quantities of information. To begin, we will say that Generics in contrast to the collections such as an ArrayList allow us to store a kind of data that is defined within them. In that way we avoid the casting process that was given in the collections of the versions 1.1 of Framework were the containers stored object type variables.
The casting process generates considerable looses of performance in the collections, this is because we don’t notice this in small quantities of registries, but it’s very easy to notice when we work with many registries, where we can notice the improvement of the performance that we can get with the generics. That’s what we’ll demonstrate today.
The idea is exactly to realize millions of interactions, doing operations both on the collections and on the Generics to notice the difference.
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace GenericsTest
{
public partial class Form1 : Form
{
int intIteraciones = 10000000;
public Form1()
{
InitializeComponent();
}
private void btnColecciones_Click(object sender, EventArgs e)
{
ArrayList al = new ArrayList();
DateTime dtmInicio = DateTime.Now;
for (int i = 0; i < intIteraciones; i++) al.Add(i);
int j;
for (int i = 0; i < intIteraciones; i++) j = (int)al[i];
DateTime dtmFin = DateTime.Now;
TimeSpan tm = dtmFin - dtmInicio;
lblColecciones.Text ="Colecciones: " + tm.ToString();
}
private void btnGenerics_Click(object sender, EventArgs e)
{
List<int> genClientes = new List<int>();
DateTime dtmInicio = DateTime.Now;
for (int i = 0; i < intIteraciones; i++) genClientes.Add(i);
int j;
for (int i = 0; i < intIteraciones; i++) j = genClientes[i];
DateTime dtmFin = DateTime.Now;
TimeSpan tm = dtmFin - dtmInicio;
lblGenerics.Text = "Generics: " + tm.ToString();
}
}
}
Well, we use the utility we know (ILDASM.exe) to see the generate IL and we see the following:
The orders of boxin and unboxin are seen clearly and it’s demonstrated that this concept of Cating or boxin and unboxin get’s defeated

In the following graphic, using the same utility ILDASM.exe we notice that there are not commands IL of Boxing and unBoxing

I hope you guys like this post and thanks again to Ivan, a special friend I got this year.
Special Thanks to Lorena Mujica (graphic designer) for checking the article, for the friendship and love.
Hugs to everybody, and I hope to post three more articles before the end of the year.
Have a Merry Christmas!!!
Greetings…
Carlos.