-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerson.cs
More file actions
111 lines (101 loc) · 2.8 KB
/
Person.cs
File metadata and controls
111 lines (101 loc) · 2.8 KB
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
104
105
106
107
108
109
110
111
using System;
namespace Lab05_CSharp
{
[Serializable]
internal class Person
{
private string name;
private string surname;
DateTime birthday;
// Определение конструкторов
public Person(string name, string surname, DateTime birthday)
{
this.name = name;
this.surname = surname;
this.birthday = birthday;
}
public Person() : this("Name", "Surname", new DateTime(2001, 9, 11)) { }
// Определение get и set методов
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
public string Surname
{
get
{
return surname;
}
set
{
surname = value;
}
}
public DateTime Birthday
{
get
{
return birthday;
}
set
{
birthday = value;
}
}
public int Year
{
get
{
return Birthday.Year;
}
set
{
Birthday = new DateTime(value, Birthday.Month, Birthday.Day);
}
}
public override string ToString()
{
return Name + " " + Surname + " " + Birthday.ToShortDateString();
}
public virtual string ToShortString()
{
return Name + " " + Surname;
}
public override bool Equals(object obj1)
{
if (obj1 == null)
{
return false;
}
Person obj = obj1 as Person;
return name.Equals(obj.name) && surname.Equals(obj.surname) && birthday.Equals(obj.birthday);
}
public static bool operator ==(Person obj1, Person obj2)
{
return obj1.name == obj2.name && obj1.surname == obj2.surname && obj1.birthday == obj2.birthday;
}
public static bool operator !=(Person obj1, Person obj2)
{
return obj1.name != obj2.name || obj1.surname != obj2.surname || obj1.birthday != obj2.birthday;
}
public override int GetHashCode()
{
return name.GetHashCode() ^ surname.GetHashCode() ^ birthday.GetHashCode();
}
public object DeepCopy()
{
Person obj = new Person();
obj.name = name;
obj.surname = surname;
obj.birthday = birthday;
return obj;
}
}
}