1
0
Files
OAiP-Presnyakov_Ilya-Practi…/GymEquipment.cs
Debug_pro d47bde6c27 upload
2026-06-07 18:27:45 +03:00

89 lines
2.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Prac8
{
public class GymEquipment : IComparable<GymEquipment>, IEquatable<GymEquipment>
{
public int Number { get; set; }
public string Name { get; set; }
public string Type { get; set; }
public string Condition { get; set; }
public string Place { get; set; }
public GymEquipment()
{
Name = string.Empty;
Type = string.Empty;
Condition = string.Empty;
Place = string.Empty;
}
public GymEquipment(int number, string name, string type, string condition, string place)
{
Number = number;
Name = name;
Type = type;
Condition = condition;
Place = place;
}
public int CompareTo(GymEquipment other)
{
if (other == null)
{
return 1;
}
int byName = string.Compare(Name, other.Name, StringComparison.OrdinalIgnoreCase);
if (byName != 0)
{
return byName;
}
return Number.CompareTo(other.Number);
}
public bool Equals(GymEquipment other)
{
if (other == null)
{
return false;
}
return Number == other.Number
&& string.Equals(Name, other.Name, StringComparison.OrdinalIgnoreCase)
&& string.Equals(Type, other.Type, StringComparison.OrdinalIgnoreCase)
&& string.Equals(Condition, other.Condition, StringComparison.OrdinalIgnoreCase)
&& string.Equals(Place, other.Place, StringComparison.OrdinalIgnoreCase);
}
public override bool Equals(object obj)
{
return Equals(obj as GymEquipment);
}
public override int GetHashCode()
{
return GetSafeHash(Name)
^ GetSafeHash(Type)
^ GetSafeHash(Condition)
^ GetSafeHash(Place)
^ Number;
}
private static int GetSafeHash(string value)
{
return value == null ? 0 : value.ToLowerInvariant().GetHashCode();
}
public override string ToString()
{
return $"№: {Number}, Название: {Name}, Тип: {Type}, Состояние: {Condition}, Место: {Place}";
}
}
}