Guest User

Untitled

a guest
Jul 23rd, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. public static class GenDAO<T> where T : IEntidad // antes static
  2. {
  3. private static List<T> BDenMemoria = new List<T>();
  4. private static int NextId = 1;
  5.  
  6. public static int Crear(T entidad)
  7. {
  8. entidad.id = NextId++;
  9. BDenMemoria.Add(entidad);
  10. return entidad.id;
  11. }
  12.  
  13. public static T Buscar(int id)
  14. {
  15. return BDenMemoria.FirstOrDefault(x => x.id == id);
  16. }
  17.  
  18. public static void Actualizar(T entidad)
  19. {
  20. int indice = BDenMemoria.FindIndex(x => x.id == entidad.id);
  21. if (indice != -1)
  22. BDenMemoria[indice] = entidad;
  23. }
  24.  
  25. public static void Eliminar(int id)
  26. {
  27. int indice = BDenMemoria.FindIndex(x => x.id == id);
  28. if (indice != -1)
  29. BDenMemoria.RemoveAt(indice);
  30. }
  31. }
  32.  
  33. GenDAO ejemplo = new GENDAO();
  34.  
  35. var lista = ejemplo.BDenMemoria;
Add Comment
Please, Sign In to add comment