/// <summary>Showing concrete equipment by index</summary> private void ShowConcreteEquipmentByIndex() { int index; BaseEquipment eq = null; Console.Clear(); Console.WriteLine("Number:"); bool result = int.TryParse(Console.ReadLine(), out index); Console.Clear(); if (result) { eq = eqCollection.GetEquipmentByIndex(index - 1); if (eq != null) { Console.WriteLine(eq.GetInfo()); } else { Console.WriteLine("The equipment wasn't found!"); } BackToMainMenu(); } else { if (RepeatEnter(TypeError.IncorrectInputValue)) { ShowConcreteEquipment(); } } }
public void SetElementByIndex(int index, BaseEquipment bq) { if (0 <= index && index < Length) { equipments[index] = bq; } }
/// <summary>Showing all equipments with oreder numbers, without checks</summary> private void ShowWholeListEquipments() { for (int i = 0; i < eqCollection.Length; i++) { BaseEquipment beq = eqCollection.GetEquipmentByIndex(i); Console.WriteLine((i + 1).ToString() + " " + beq.GetInfo()); } }
/// <summary>Copy elements to increase the array</summary> private BaseEquipment[] CopyValuesForIncrease() { BaseEquipment[] result = new BaseEquipment[equipments.Length + 1]; for (int i = 0; i < equipments.Length; i++) { result[i] = equipments[i]; } return(result); }
/// <summary>Copy elements to decrease the array usinng integer variable 'index'</summary> private BaseEquipment[] CopyValuesForDecrease(int index) { BaseEquipment[] result = new BaseEquipment[equipments.Length - 1]; int j = 0; for (int i = 0; i < equipments.Length; i++) { if (i == index) { continue; } result[j] = equipments[i]; j++; } return(result); }
/// <summary>Getting equipment from the collection by the name</summary> public BaseEquipment GetEquipmentByName(string name) { if (Length == 0) { return(null); } BaseEquipment result = null; foreach (BaseEquipment eq in equipments) { if (eq.Name == name) { result = eq; break; } } return(result); }
/// <summary>Showing concrete equipment by name</summary> private void ShowConcreteEquipmentByName() { Console.Clear(); Console.WriteLine("Name:"); string ans = Console.ReadLine(); Console.Clear(); BaseEquipment eq = eqCollection.GetEquipmentByName(ans); if (eq != null) { Console.WriteLine(eq.GetInfo()); } else { Console.WriteLine("The equipment wasn't found!"); } BackToMainMenu(); }
/// <summary>Copy elements to decrease the array usinng string variable 'name'</summary> private BaseEquipment[] CopyValuesForDecrease(string name) { BaseEquipment[] result = new BaseEquipment[equipments.Length - 1]; int index = 0; bool found = false; for (int i = 0; i < equipments.Length; i++) { if (equipments[i].Name == name && !found) { found = true; continue; } result[index] = equipments[i]; index++; } return(result); }
/// <summary>Adding an equipment to the end of the collection</summary> public void Add(BaseEquipment eq) { IncreaseSize(); equipments[equipments.Length - 1] = eq; }