-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWriteFileClassPeopleVersion2.cs
More file actions
64 lines (59 loc) · 1.82 KB
/
WriteFileClassPeopleVersion2.cs
File metadata and controls
64 lines (59 loc) · 1.82 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
using System;
using System.IO;
using static System.Console;
namespace WriteFileClassPeople
{
public class People
{
private readonly int year, month, day;
private readonly DateTime birthDate;
private string Name { get; set; }
private string Sex { get; set; }
public People()
{
Write("ФИО: ");
Name = ReadLine();
Write("Укажите пол: ");
Sex = ReadLine();
Write("Год рождения: ");
year = GetInt();
Write("Месяц рождения: ");
month = GetInt();
Write("День рождения: ");
day = GetInt();
birthDate = new DateTime(year, month, day);
}
private int Age()
{
return DateTime.Now.Subtract(birthDate).Days / 365;
}
public string ToFile()
{
return $"Имя: {Name} пол: {Sex} Возраст {Age()}";
}
private int GetInt()
{
return int.Parse(ReadLine());
}
}
class Program
{
static void Main(string[] args)
{
string yes = "y";
do
{
People people = new People();
Console.WriteLine();
using (StreamWriter file = File.AppendText(@"d:\people.csv"))
{
file.WriteLine(people.ToFile());
Console.WriteLine("Запись в файл прошла успешно!");
}
Write("Хотете продолжить?: Y - да: ");
yes = ReadLine();
}
while (yes == "Y" || yes == "y");
}
}
}