Advertisement
Fhernd

Lista.cs

Nov 25th, 2017
2,379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. public class Lista<T>
  2. {
  3.     private T[] arreglo;
  4.    
  5.     public Lista(int tamanio)
  6.     {
  7.         arreglo = new T[tamanio];
  8.     }
  9.    
  10.     public T ObtenerElemento(int indice)
  11.     {
  12.         return arreglo[indice];
  13.     }
  14.    
  15.     public void AgregarElemento(int indice, T valor)
  16.     {
  17.         arreglo[indice] = valor;
  18.     }
  19.    
  20.     public static void Main ()
  21.     {
  22.         Lista<int> listaEnteros = new Lista<int>(5);
  23.        
  24.         listaEnteros.AgregarElemento(0, 2);
  25.         listaEnteros.AgregarElemento(1, 3);
  26.         listaEnteros.AgregarElemento(2, 5);
  27.         listaEnteros.AgregarElemento(3, 7);
  28.         listaEnteros.AgregarElemento(4, 11);
  29.        
  30.         Lista<double> listaDoubles = new Lista<double>(3);
  31.        
  32.         listaDoubles.AgregarElemento(7.11);
  33.         listaDoubles.AgregarElemento(13.17);
  34.         listaDoubles.AgregarElemento(19.23);
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement