Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created December 15, 2013 20:00
Show Gist options
  • Save Fhernd/7977406 to your computer and use it in GitHub Desktop.
Save Fhernd/7977406 to your computer and use it in GitHub Desktop.
Demostración de polimorfismo paramétrico en C#.
public class Lista<T>
{
private T[] arreglo;
public Lista(int tamanio)
{
arreglo = new T[tamanio];
}
public T ObtenerElemento(int indice)
{
return arreglo[indice];
}
public void AgregarElemento(int indice, T valor)
{
arreglo[indice] = valor;
}
public static void Main ()
{
Lista<int> listaEnteros = new Lista<int>(5);
listaEnteros.AgregarElemento(0, 2);
listaEnteros.AgregarElemento(1, 3);
listaEnteros.AgregarElemento(2, 5);
listaEnteros.AgregarElemento(3, 7);
listaEnteros.AgregarElemento(4, 11);
Lista<double> listaDoubles = new Lista<double>(3);
listaDoubles.AgregarElemento(7.11);
listaDoubles.AgregarElemento(13.17);
listaDoubles.AgregarElemento(19.23);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment