Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class GenDAO<T> where T : IEntidad // antes static
- {
- private static List<T> BDenMemoria = new List<T>();
- private static int NextId = 1;
- public static int Crear(T entidad)
- {
- entidad.id = NextId++;
- BDenMemoria.Add(entidad);
- return entidad.id;
- }
- public static T Buscar(int id)
- {
- return BDenMemoria.FirstOrDefault(x => x.id == id);
- }
- public static void Actualizar(T entidad)
- {
- int indice = BDenMemoria.FindIndex(x => x.id == entidad.id);
- if (indice != -1)
- BDenMemoria[indice] = entidad;
- }
- public static void Eliminar(int id)
- {
- int indice = BDenMemoria.FindIndex(x => x.id == id);
- if (indice != -1)
- BDenMemoria.RemoveAt(indice);
- }
- }
- GenDAO ejemplo = new GENDAO();
- var lista = ejemplo.BDenMemoria;
Add Comment
Please, Sign In to add comment