public void Delete(int index) { if (index < 0 || index > _pencils.Length - 1) { Console.WriteLine("Index is out of range"); return; } for (int i = index; i < _pencils.Length; i++) { if (index == _pencils.Length - 1) { return; } _pencils[index] = _pencils[index + 1]; } var newArr = new Pencil[_pencils.Length - 1]; }
static void Main(string[] args) { var pencilsRepository = new PencilsRepository(24); var pencil = new Pencil { Id = 0, Brand = "Marc", Price = 25, Size = 25 }; pencilsRepository.Add(pencil); pencilsRepository.Add(pencil); pencilsRepository.Add(pencil); pencilsRepository.WriteToFile(); var pencilNew = pencilsRepository.ReadFromFile(); Console.ReadKey(); }
public override void Add(Pencil pencil) { _pencils[_lastIndex++] = pencil; }
public abstract void Add(Pencil pencil);