-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAddress.cs
84 lines (71 loc) · 2.26 KB
/
Address.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
using System;
namespace LabWork_10
{
public class Address : Place
{
private string street = "Улица не указана";
private int houseNum = 1;
public string Street
{
get => street;
set
{
if (!String.IsNullOrWhiteSpace(value)) street = value;
else street = "Улица не указана";
}
}
public int HouseNumber
{
get => houseNum;
set
{
if (value > 0) houseNum = value;
else houseNum = 1;
}
}
public Address() : base("Адрес без названия") { }
public Address(string name, string street, int house)
{
if (String.IsNullOrWhiteSpace(name)) name = "Адрес без названия";
Name = name;
(Street, HouseNumber) = (street, house);
}
public new void PrintInfo()
{
base.PrintInfo();
Console.WriteLine("" +
$"Улица: {Street}\n" +
$"Дом: {HouseNumber}\n");
}
public override void PrintInformation()
{
base.PrintInformation();
Console.WriteLine("" +
$"Улица: {Street}\n" +
$"Дом: {HouseNumber}");
}
public override string ToString()
{
return base.ToString() +
$"\nУлица: {Street}\n" +
$"Дом: {HouseNumber}";
}
public new object Clone()
{
return new Address(Name, Street, HouseNumber);
}
public new object ShallowCopy()
{
return (Address)this.MemberwiseClone();
}
public new int CompareTo(object obj)
{
Address temp = (Address)obj;
if (String.Compare(temp.Name, this.Name) != 0) return String.Compare(temp.Name, this.Name);
if (String.Compare(temp.Street, this.Street) != 0) return String.Compare(temp.Street, this.Street);
if (temp.HouseNumber > this.HouseNumber) return 1;
if (temp.HouseNumber < this.HouseNumber) return -1;
return 0;
}
}
}