Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created October 19, 2013 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/7054329 to your computer and use it in GitHub Desktop.
Save Fhernd/7054329 to your computer and use it in GitHub Desktop.
Demostración de un destructor en C#.
using System;
using System.Diagnostics;
public class Contador
{
private Stopwatch cronometro;
public Contador ()
{
cronometro = Stopwatch.StartNew ();
Console.WriteLine ("Se ha instanciado un objeto.");
}
public void MostrarDuracion ()
{
Console.WriteLine ("La instancia {0} ha tenido una duración de: {1}.", this, cronometro.Elapsed);
}
~Contador ()
{
Console.WriteLine ("Se iniciado la finalización del objeto.");
cronometro.Stop ();
Console.WriteLine ("La instancia {0} ha tenido una duración de: {1}.", this, cronometro.Elapsed);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment