Вот само задание: 1. Создать виртуальный метод в родительском классе. 2. Создать 2 дочерних классы согласно варианту. 3. В одном из классов преемников переопределить виртуальный метод, обеспечив выполнение виртуального метода родительского класса + собственные элементы. 4. В одном из классов преемников переопределить виртуальный метод, без выполнения элементов виртуального метода родительского класса (только собственные Элементы). (Пожалуйста кто разбирается можете немного его исправить на более правильный вариант ибо я новичок и не особо разбираюсь) У меня просто каждое предыдущее задание зависит от следующего и мне нужен более правильно код :с Вот сам код: using System; namespace Biblioteka_ { class Program { static void Main(string[] args) { Book[] b = new Book[10]; Random rnd = new Random(); for (int i = 0; i < b.Length - 8; i++) { b[i] = i % 2 == 0 ? new Book(i, "Autor:" + i, "Name:" + i, "Vudannya:" + i, rnd.Next(100, 1000)) : new Book(i, "Name:" + i); b[i].Vuvod(); b[i].kilk(); } for (int i = 0; i < b.Length - 8; i++) { if (b[i].cina < 500) b[i].Vuvod(); } Period p = new Period(3, "lsaxzfed", "das"); p.Vuvod(); Console.ReadKey(); } } } using System; using System.Collections.Generic; using System.Text; namespace Biblioteka_ { class Book { private string v1; private string v2; private int v3; public int id { set; get; } public string pib { set; get; } public string name { set; get; } public int year { set; get; } public string vudannya { set; get; } public double cina { set; get; } public Book() { } public Book(int id, string name, string name1, string mounth) { this.id = id; this.name = name; Console.WriteLine("Vvedennya vudannya"); vudannya = Console.ReadLine(); } public Book(int id, string pib, string name, int year, string vudannya, double cina) { this.id = id; this.pib = pib; this.name = name; this.year = year; this.vudannya = vudannya; this.cina = cina; } public Book(int id, string name, string v1, string v2, int v3) : this(id, name) { this.v1 = v1; this.v2 = v2; this.v3 = v3; } public Book(int id, string name) { this.id = id; this.name = name; } public virtual void Vuvod() { Console.WriteLine("id : {0} People : {1} Name : {2} Vid : {3} Cena : {4}", id, pib, name, vudannya, cina); } public void info2(int c) { if (cina < c) Console.WriteLine("id - {0} avtor - {1} nazva - {2} vid - {3} cena - {4}", id, pib, name, vudannya, cina); } public void kilk() { cina = cina - 100; } } } using System; namespace Biblioteka_ { internal class Period : Book { public string mouth { set; get; } public string LastName { get; internal set; } public string FirstName { get; internal set; } public Period() { } public Period(string mounth) { this.mouth = mouth; } public Period(int id, string pib, string name, string mounth) : base(id, pib, name, mounth) { this.id = id; this.pib = pib; this.name = name; this.mouth = mounth; } public override void Vuvod() { Console.WriteLine("Выделить время собрания"); } private int v1; private string v2; private string v3; public Period(int v1, string v2, string v3) { this.v1 = v1; this.v2 = v2; this.v3 = v3; } } } using System; using System.Collections.Generic; using System.Text; namespace Biblioteka_ { class BatClass1 { public virtual void BatZboru() { Console.WriteLine("Пригласить родителей"); } } class Period1 : BatClass1 { public override void BatZboru() { base.BatZboru(); } } } Код using System; namespace Biblioteka_ { class Program { static void Main(string[] args) { Book[] b = new Book[10]; Random rnd = new Random(); for (int i = 0; i < b.Length - 8; i++) { b[i] = i % 2 == 0 ? new Book(i, "Autor:" + i, "Name:" + i, "Vudannya:" + i, rnd.Next(100, 1000)) : new Book(i, "Name:" + i); b[i].Vuvod(); b[i].kilk(); } for (int i = 0; i < b.Length - 8; i++) { if (b[i].cina < 500) b[i].Vuvod(); } Period p = new Period(3, "lsaxzfed", "das"); p.Vuvod(); Console.ReadKey(); } } } using System; using System.Collections.Generic; using System.Text; namespace Biblioteka_ { class Book { private string v1; private string v2; private int v3; public int id { set; get; } public string pib { set; get; } public string name { set; get; } public int year { set; get; } public string vudannya { set; get; } public double cina { set; get; } public Book() { } public Book(int id, string name, string name1, string mounth) { this.id = id; this.name = name; Console.WriteLine("Vvedennya vudannya"); vudannya = Console.ReadLine(); } public Book(int id, string pib, string name, int year, string vudannya, double cina) { this.id = id; this.pib = pib; this.name = name; this.year = year; this.vudannya = vudannya; this.cina = cina; } public Book(int id, string name, string v1, string v2, int v3) : this(id, name) { this.v1 = v1; this.v2 = v2; this.v3 = v3; } public Book(int id, string name) { this.id = id; this.name = name; } public virtual void Vuvod() { Console.WriteLine("id : {0} People : {1} Name : {2} Vid : {3} Cena : {4}", id, pib, name, vudannya, cina); } public void info2(int c) { if (cina < c) Console.WriteLine("id - {0} avtor - {1} nazva - {2} vid - {3} cena - {4}", id, pib, name, vudannya, cina); } public void kilk() { cina = cina - 100; } } } using System; namespace Biblioteka_ { internal class Period : Book { public string mouth { set; get; } public string LastName { get; internal set; } public string FirstName { get; internal set; } public Period() { } public Period(string mounth) { this.mouth = mouth; } public Period(int id, string pib, string name, string mounth) : base(id, pib, name, mounth) { this.id = id; this.pib = pib; this.name = name; this.mouth = mounth; } public override void Vuvod() { Console.WriteLine("Выделить время собрания"); } private int v1; private string v2; private string v3; public Period(int v1, string v2, string v3) { this.v1 = v1; this.v2 = v2; this.v3 = v3; } } } using System; using System.Collections.Generic; using System.Text; namespace Biblioteka_ { class BatClass1 { public virtual void BatZboru() { Console.WriteLine("Пригласить родителей"); } } class Period1 : BatClass1 { public override void BatZboru() { base.BatZboru(); } } } Спасибо!
b = i % 2 == 0 ? new Book(i, "Autor:" + i, "Name:" + i, "Vudannya:" + i, rnd.Next(100, 1000)) : new Book(i, "Name:" + i); плохая строка...
1. Плохой нейминг полей и методов; 2. Не пиши имя полей и методов транслитом; 3. При именовании приватных полей используй префикс нижнего подчеркивания вначале имени. Например: private int _randomNumber;