Происходит запись в текстовый файл таких свойств как Автор, Имя, Фамилия, Организация, ИИН, ID и т.д как можно вывести из файла только Имя и Фамилию? static void Main(string[] args) { string path = "C:\\textFile.txt"; Console.WriteLine("1 - Зарегистрироваться как физическое лицо"); Console.WriteLine("2 - Зарегистрироваться как юридическое лицо"); Console.WriteLine("3 - Просмотреть список всех зарегистрированных лиц"); Console.WriteLine("4 - Сделать вывод списка физ лиц. Упорядочить список физ. лиц по Фамилии, Имени, Отчеству. "); byte pick = Convert.ToByte(Console.ReadLine()); List<Person> people = new List<Person>(); List<Organization> peopleOrg = new List<Organization>(); if (pick == 1) { Console.WriteLine("Автор - "); string _creator = Console.ReadLine(); Console.WriteLine("Имя - "); string _name = Console.ReadLine(); Console.WriteLine("Фамилия - "); string _lastName = Console.ReadLine(); Console.WriteLine("ИИН - "); string _iin = Console.ReadLine(); people.Add(new Person(_creator, _name, _lastName, _iin)); using (StreamWriter sw = new StreamWriter(path, true, System.Text.Encoding.Default)) { foreach (var item in people) { sw.WriteLine(); sw.Write($"{item.Name}\t"); sw.Write($"{item.LastName}\t"); sw.Write($"{item.Creator}\t"); sw.Write($"{item.Id}\t"); sw.Write($"{item.Iin}\t"); sw.Write($"{item.DateOfCreaction}\t"); } } } if (pick == 2) { Console.WriteLine("ИИН - "); string _iin = Console.ReadLine(); Console.WriteLine("Автор - "); string _creator = Console.ReadLine(); Console.WriteLine("Имя организации - "); string _orgname = Console.ReadLine(); peopleOrg.Add(new Organization(_orgname, _creator, _iin)); using (StreamWriter sw = new StreamWriter(path, true, System.Text.Encoding.Default)) { foreach (var item in peopleOrg) { sw.WriteLine(); sw.Write($"{item.Creator}\t"); sw.Write($"{item.OrganizationName}\t"); sw.Write($"{item.Id}\t"); sw.Write($"{item.Iin}\t"); sw.Write($"{item.DateOfCreaction}\t"); } } } if (pick == 3) { using (StreamReader sr = new StreamReader(path)) { Console.WriteLine(sr.ReadToEnd()); } } if (pick == 4) { } } Код static void Main(string[] args) { string path = "C:\\textFile.txt"; Console.WriteLine("1 - Зарегистрироваться как физическое лицо"); Console.WriteLine("2 - Зарегистрироваться как юридическое лицо"); Console.WriteLine("3 - Просмотреть список всех зарегистрированных лиц"); Console.WriteLine("4 - Сделать вывод списка физ лиц. Упорядочить список физ. лиц по Фамилии, Имени, Отчеству. "); byte pick = Convert.ToByte(Console.ReadLine()); List<Person> people = new List<Person>(); List<Organization> peopleOrg = new List<Organization>(); if (pick == 1) { Console.WriteLine("Автор - "); string _creator = Console.ReadLine(); Console.WriteLine("Имя - "); string _name = Console.ReadLine(); Console.WriteLine("Фамилия - "); string _lastName = Console.ReadLine(); Console.WriteLine("ИИН - "); string _iin = Console.ReadLine(); people.Add(new Person(_creator, _name, _lastName, _iin)); using (StreamWriter sw = new StreamWriter(path, true, System.Text.Encoding.Default)) { foreach (var item in people) { sw.WriteLine(); sw.Write($"{item.Name}\t"); sw.Write($"{item.LastName}\t"); sw.Write($"{item.Creator}\t"); sw.Write($"{item.Id}\t"); sw.Write($"{item.Iin}\t"); sw.Write($"{item.DateOfCreaction}\t"); } } } if (pick == 2) { Console.WriteLine("ИИН - "); string _iin = Console.ReadLine(); Console.WriteLine("Автор - "); string _creator = Console.ReadLine(); Console.WriteLine("Имя организации - "); string _orgname = Console.ReadLine(); peopleOrg.Add(new Organization(_orgname, _creator, _iin)); using (StreamWriter sw = new StreamWriter(path, true, System.Text.Encoding.Default)) { foreach (var item in peopleOrg) { sw.WriteLine(); sw.Write($"{item.Creator}\t"); sw.Write($"{item.OrganizationName}\t"); sw.Write($"{item.Id}\t"); sw.Write($"{item.Iin}\t"); sw.Write($"{item.DateOfCreaction}\t"); } } } if (pick == 3) { using (StreamReader sr = new StreamReader(path)) { Console.WriteLine(sr.ReadToEnd()); } } if (pick == 4) { } } class CounterAgent { public Guid Id { get; } public string Iin { get; set; } public DateTime DateOfCreaction { get; set; } //Дата создания public string Creator { get; set; } //Автор public DateTime DateOfChange { get; set; } // Дата изменения public string ChangeAuthor { get; private set; } //Автор изменения public CounterAgent(string creator, string iin) { this.Creator = creator; this.DateOfCreaction = DateTime.Now; this.Id = Guid.NewGuid(); if (iin.Length == 12) { this.Iin = iin; } else throw new ArgumentException("ИИН должен состоять из 12 символов!"); } } Код class CounterAgent { public Guid Id { get; } public string Iin { get; set; } public DateTime DateOfCreaction { get; set; } //Дата создания public string Creator { get; set; } //Автор public DateTime DateOfChange { get; set; } // Дата изменения public string ChangeAuthor { get; private set; } //Автор изменения public CounterAgent(string creator, string iin) { this.Creator = creator; this.DateOfCreaction = DateTime.Now; this.Id = Guid.NewGuid(); if (iin.Length == 12) { this.Iin = iin; } else throw new ArgumentException("ИИН должен состоять из 12 символов!"); } } class Person : CounterAgent { public string Name { get; set; } public string LastName { get; set; } public Person(string name ,string lastName,string creator, string iin) : base(creator, iin) { Name = name; LastName = lastName; } } Код class Person : CounterAgent { public string Name { get; set; } public string LastName { get; set; } public Person(string name ,string lastName,string creator, string iin) : base(creator, iin) { Name = name; LastName = lastName; } } class Organization : CounterAgent { public string OrganizationName { get; set; } public Organization(string orgName, string creator, string iin) : base(creator, iin) { this.OrganizationName = orgName; } } Код class Organization : CounterAgent { public string OrganizationName { get; set; } public Organization(string orgName, string creator, string iin) : base(creator, iin) { this.OrganizationName = orgName; } }
Считал файл в класс и вывел все в консоль, а вообще советую написать нормально со switch case и зачем тебе нужен streamwriter, когда есть методы в system.io
Ebaysher, С if получается говнокод, зачем это делать когда есть switch? А вывод свойства обычно так же как и вывод переменной класса через объект (example.var)