-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRegion.cs
103 lines (83 loc) · 2.66 KB
/
Region.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System;
namespace LabWork_10
{
public class Region : Place
{
public Place BasePlace
{
get => new Place(Name);
}
private int population;
public int Population //Население региона
{
get => population;
set
{
if (value >= 0) population = value;
else population = 0;
}
}
public Region() : base("Регион без имени") { }
public Region(string name, int population = 0)
{
if (String.IsNullOrWhiteSpace(name)) name = "Регион без имени";
Name = name;
Population = population;
}
public new void PrintInfo()
{
base.PrintInfo();
Console.WriteLine($"Население: {Population}");
}
public override void PrintInformation()
{
base.PrintInformation();
Console.WriteLine($"Население: {Population}");
}
public override string ToString()
{
return base.ToString() + $"\nНаселение: {Population}";
}
public new object Clone()
{
return new Region(Name, Population);
}
public new object ShallowCopy()
{
return (Region)this.MemberwiseClone();
}
public new int CompareTo(object obj)
{
Region temp = (Region)obj;
if (String.Compare(temp.Name, this.Name) != 0) return String.Compare(temp.Name, this.Name);
if (this.Population > temp.Population) return 1;
if (this.Population < temp.Population) return -1;
return 0;
}
public static bool operator >(Region left, Region right)
{
return left.CompareTo(right) == 1;
}
public static bool operator <(Region left, Region right)
{
return left.CompareTo(right) == -1;
}
public static bool operator ==(Region left, Region right)
{
return string.Compare(left.Name, right.Name) == 0 && left.Population == right.Population;
}
public static bool operator !=(Region left, Region right)
{
return string.Compare(left.Name, right.Name) != 0 || left.Population != right.Population;
}
public override bool Equals(object obj)
{
if (this.GetType() != obj.GetType()) return false;
return this == (Region)obj;
}
public override int GetHashCode()
{
return ToString().GetHashCode();
}
}
}