Created
December 15, 2013 20:00
-
-
Save Fhernd/7977406 to your computer and use it in GitHub Desktop.
Demostración de polimorfismo paramétrico en C#.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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