Класс описаний книг и необработанное исключение типа "System.StackOverflowException" - C#

Узнай цену своей работы

Формулировка задачи:

Здравствуйте. Делаю задание и выбрасывает такое исключение. Помогите найти причину. Задание: Создать класс описаний книг. Поля должны быть закрытыми. Для всех полей должны быть созданы свойства. В конструкторе осуществляется инициализация всех полей. Необходимо создать метод, выводящий описание книги в строку (переопределение метода ToString). Создать два объекта описаний книг. Вызвать для них метод осуществляющий вывод строки описания. Создать массив(размерностью не более 5) объектов.Создать статический метод для упорядочивания(по числу страниц) данного масива.
Листинг программы
  1. using System;
  2. namespace Kontrolnaya
  3. {
  4. class Program
  5. {
  6. static void Main()
  7. {
  8. CBookCard oneBook = new CBookCard("Lermontov","Kniga","Shustrie",2012,"243","10");
  9. CBookCard twoBook = new CBookCard("Pushkin", "Kniga", "Dalnie", 2002, "269", "6");
  10. Console.WriteLine(oneBook);
  11. Console.WriteLine(twoBook);
  12. }
  13. }
  14. class CBookCard
  15. {
  16. public CBookCard(string Autor,string Tittle,string Publish,int Year,string Pages,string ISBN)
  17. {
  18. this.Autor = Autor;
  19. this.Tittle = Tittle;
  20. this.Publish = Publish;
  21. this.Year = Year;
  22. this.Pages = Pages;
  23. this.ISBN = ISBN;
  24. }
  25. public string Autor
  26. {
  27. get
  28. {
  29. return Autor;
  30. }
  31. set
  32. {
  33. Autor = Autor;
  34. }
  35. }
  36. public string Tittle
  37. {
  38. get
  39. {
  40. return Tittle;
  41. }
  42. set
  43. {
  44. Tittle = Tittle;
  45. }
  46. }
  47. public string Publish
  48. {
  49. get
  50. {
  51. return Publish;
  52. }
  53. set
  54. {
  55. Publish = Publish;
  56. }
  57. }
  58. public int Year
  59. {
  60. get
  61. {
  62. return Year;
  63. }
  64. set
  65. {
  66. Year = Year;
  67. }
  68. }
  69. public string Pages
  70. {
  71. get
  72. {
  73. return Pages;
  74. }
  75. set
  76. {
  77. Pages = Pages;
  78. }
  79. }
  80. public string ISBN
  81. {
  82. get
  83. {
  84. return ISBN;
  85. }
  86. set
  87. {
  88. ISBN = ISBN;
  89. }
  90. }
  91. public override string ToString()
  92. {
  93. return "Автор: "+Autor+"Заглавие: "+Tittle+"Издательство: "+Publish+"Год издания: "+Year+"Число страниц: "+Pages+"ISBN: "+ISBN;
  94. }
  95. }
  96. }

Решение задачи: «Класс описаний книг и необработанное исключение типа "System.StackOverflowException"»

textual
Листинг программы
  1.   class CBookCard
  2.   {
  3.     public CBookCard(string autor, string tittle, string publish, int year, int pages, string isbn)
  4.     {
  5.       Autor = autor;
  6.       Tittle = tittle;
  7.       Publish = publish;
  8.       Year = year;
  9.       Pages = pages;
  10.       ISBN = isbn;
  11.     }
  12.  
  13.     public string Autor { get; set; }
  14.     public string Tittle { get; set; }
  15.     public string Publish { get; set; }
  16.     public int Year { get; set; }
  17.     public int Pages { get; set; }
  18.     public string ISBN { get; set; }
  19.  
  20.     public override string ToString()
  21.     {
  22.       return "Автор: " + Autor + " Заглавие: " + Tittle + " Издательство: " + Publish + " Год издания: " + Year + " Число страниц: " + Pages + " ISBN: " + ISBN + "\n";
  23.     }
  24.   }
  25.  
  26.   class Program
  27.   {
  28.     static void QuickSort(CBookCard[] arr, int left, int right)
  29.     {
  30.       var x = arr[(left + right) / 2].Pages;
  31.       var i = left;
  32.       var j = right;
  33.       while (i <= j)
  34.       {
  35.         while (arr[i].Pages < x) i++;
  36.         while (arr[j].Pages > x) j--;
  37.         if (i <= j)
  38.         {
  39.           var tmp = arr[i];
  40.           arr[i] = arr[j];
  41.           arr[j] = tmp;
  42.           i++;
  43.           j--;
  44.         }
  45.       }
  46.       if (i < right)
  47.       {
  48.         QuickSort(arr, i, right);
  49.       }
  50.       else
  51.       {
  52.         if (left < j)
  53.         {
  54.           QuickSort(arr, left, j);
  55.         }
  56.       }
  57.     }
  58.  
  59.     static void Main(string[] args)
  60.     {
  61.       var bookArr = new CBookCard[] {
  62.        new CBookCard("Pervaya", "jhfg", "publish", 2010, 134, ""),
  63.        new CBookCard("Vtoraya", "jhfg", "publish", 2010, 1340, ""),
  64.        new CBookCard("Tretya", "jhfg", "publish", 2010, 58, ""),
  65.        new CBookCard("Chetvertaya", "jhfg", "publish", 2010, 293, ""),
  66.        new CBookCard("Pyataya", "jhfg", "publish", 2010, 15, "")
  67.     };
  68.       QuickSort(bookArr, 0, bookArr.Length - 1);
  69.       foreach(var item in bookArr)
  70.       {
  71.         Console.WriteLine(item.ToString());
  72.       }
  73.       Console.ReadKey(true);
  74.     }
  75.   }

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

12   голосов , оценка 4.167 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы