Advertisement
Guest User

Repo

a guest
Jun 22nd, 2019
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace Repository
  6. {
  7.     public class Repository
  8.     {
  9.         private List<Person> collection;
  10.         public Repository()
  11.         {
  12.             collection = new List<Person>();
  13.         }
  14.         public int Count => collection.Count;
  15.         public void Add(Person person)
  16.         {
  17.             collection.Add(person);
  18.         }
  19.         public Person Get(int id)
  20.         {
  21.             return collection[id];
  22.         }
  23.         public void Update(int id, Person newPerson)
  24.         {
  25.             Person person = newPerson;
  26.             collection[id] = person;
  27.         }
  28.         public bool Delete(int id)
  29.         {
  30.             if (collection.Contains(collection[id]))
  31.             {
  32.                 collection.Remove(collection[id]);
  33.                 return true;
  34.             }
  35.             else
  36.             {
  37.                 return false;
  38.             }
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement