public int YearOfPublication;
public Article(string title, string author, int yearOfPublication)
this.YearOfPublication = yearOfPublication;
public override bool Equals(object obj)
Article art = (Article)obj;
if(Title != art.Title || Author != art.Author || YearOfPublication != art.YearOfPublication)
public override string ToString()
return String.Format("Название: {0}{1}Автор: {2}{1}Год публикации: {3}", Title, Environment.NewLine, Author, YearOfPublication);
public abstract string Name { get; set;}
public abstract double GetArea();
public abstract double GetPerimeter();
public abstract void GetInfo();
public override string Name
name = value.Length > 0 ? value : name;
public Square(string name, double area, double perimeter)
public override double GetArea()
public override double GetPerimeter()
public override void GetInfo()
Console.WriteLine("Название фигуры: {0}", name);
Console.WriteLine("Площадь: {0}", Area);
Console.WriteLine("Периметр: {0}", Perimeter);
class RandomPlus : Random
public string GetRandomString(int len)
for (int i = 0; i <= len; i++)
ret += (char)Next('a', 'z' + 1);
public static void Main()
Article art1 = new Article();
Article art2 = new Article("TOP", "Mo", 2009);
Console.WriteLine("Вызов метода ToString явно: ");
Console.WriteLine(art1.ToString());
Console.WriteLine("Вызов метода ToString неявно: ");
Console.Write("Проверка, одинаковые ли объекты: {0}", art1.Equals(art2) ? "Да" : "Нет");
Square square = new Square("Квадрат", 50, 27);
RandomPlus r = new RandomPlus();
Console.WriteLine("Случайная строка из 50 символов: {0}", r.GetRandomString(50));