Помогите найти причину StackOverflowException - C#

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

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

Помогите пожалуйста, написал программу, но она матерится необработанным исключением, задание такое: Доработать задание лабораторной работы №1 использовав следующие изменения: 1. Добавить класс потомок; 2. Добавить метод реализуемый в потомке 3. Использовать в классе потомке доступ к полям базового класса 4. Добавить класс клиент в котором использовать клиентский статический и динамический ме-тод. 5. Выполнить описание добавляемых методов. Вродебы как все сделано, но пахать она не хочет(
Листинг программы
  1. using System;
  2. using System.Linq;
  3. namespace Задание
  4. {
  5. class Vector
  6. {
  7. protected int[] items;
  8. protected int Bound;
  9. protected static bool test;
  10. public Vector(int Bound, int length)
  11. {
  12. items = new int[length];
  13. this.Bound = Bound;
  14. }
  15. public int Length
  16. {
  17. set { Length = value; }
  18. get { return items.Length; }
  19. }
  20. public int this[int index]
  21. {
  22. get
  23. {
  24. return items[index];
  25. }
  26. set
  27. {
  28. items[index] = value;
  29. }
  30. }
  31. public void SumVector(int length, Vector First, Vector Second)
  32. {
  33. if (First.Bound != Second.Bound || First.Length != Second.Length)
  34. throw new InvalidOperationException();
  35. Console.Write("Сложение: ");
  36. for (int Count = 0; Count < Length; Count++)
  37. {
  38. First[Count] += Second[Count];
  39. }
  40. }
  41. public void SubsVector(int length, Vector First, Vector Second)
  42. {
  43. if (First.Bound != Second.Bound || First.Length != Second.Length)
  44. throw new InvalidOperationException();
  45. Console.Write("Вычитание: ");
  46. for (int Count = 0; Count < Length; Count++)
  47. {
  48. First[Count] -= Second[Count];
  49. }
  50. }
  51. public void MultVector(int k, Vector First)
  52. {
  53. Console.Write("Умножение на скаляр: ");
  54. for (int i = 0; i < First.Length; i++)
  55. First.items[i] = k * First.items[i];
  56. }
  57. public void DivVector(int k, Vector First)
  58. {
  59. Console.Write("Деление: ");
  60. for (int i = 0; i < First.Length; i++)
  61. First.items[i] = First.items[i] / k;
  62. }
  63. public void ToConsoleAll()
  64. {
  65. Console.WriteLine(string.Join(" ", items));
  66. }
  67. public void ToConsoleIndex(int Search)
  68. {
  69. try
  70. {
  71. int index = Search;
  72. Console.WriteLine("Искомый элемент: {0}", this[index]);
  73. }
  74. catch
  75. {
  76. Console.Write("Элемента по этому индексу не существует.");
  77. }
  78. }
  79. public bool Test()
  80. {
  81. if (Bound % 2 == 0)
  82. {
  83. test = true;
  84. }
  85. else
  86. {
  87. test = false;
  88. }
  89. return test;
  90. }
  91. }
  92. class client //4. класс клиент в котором использованы клиентский статический и динамический ме-тод.
  93. {
  94. string Name;
  95. static int kurs;
  96. public void Har(string Name, int Kurs)
  97. {
  98. this.Name = Name;
  99. kurs = Kurs;
  100. Console.WriteLine("\nИмя Вектора - {0}", Name);
  101. Say_Kurs();
  102. }
  103. public static void Say_Kurs()
  104. {
  105. Console.WriteLine("Курс - {0}", kurs);
  106. }
  107. }
  108.  
  109. class PVector : Vector //1.класс потомок;
  110. {
  111. public PVector(string Name, int Kurs, int length, int Bound)
  112. : base(length, Bound)
  113. {
  114. client Third = new client();
  115. Third.Har(Name, Kurs);
  116. }
  117. public void Metod()
  118. {
  119. if (Test())
  120. {
  121. Console.WriteLine("Четная");
  122. }
  123. else
  124. {
  125. Console.WriteLine("Нечетная");
  126. }
  127. }
  128. public void MultLength(int b)
  129. {
  130. Length += b;//3. Использование в классе потомке доступа к полям базового класса
  131. Bound += b;
  132. Console.WriteLine(" ");
  133. }
  134. }
  135. class Program
  136. {
  137. static void Main(string[] args)
  138. {
  139. int length;
  140. int Search;
  141. string Name;
  142. int Kurs;
  143. Console.Write("Введите длину векторов First и Second: ");
  144. length = Convert.ToInt32(Console.ReadLine());
  145. Vector First = new Vector(1, length);
  146. Vector Second = new Vector(1, length);
  147. Random R = new Random();
  148. Console.Write("Вектор First: ");
  149. for (int Count = 0; Count < length; Count++)
  150. {
  151. First[Count] = R.Next(1, 10);
  152. Console.Write("{0} ", First[Count]);
  153. }
  154. Console.ReadLine();
  155. Console.Write("Вектор Second: ");
  156. for (int Count = 0; Count < length; Count++)
  157. {
  158. Second[Count] = R.Next(-10, -1);
  159. Console.Write("{0} ", Second[Count]);
  160. }
  161. Console.ReadLine();
  162. First.SumVector(length, First, Second);
  163. First.ToConsoleAll();
  164. First.SubsVector(length, First, Second);
  165. First.ToConsoleAll();
  166. First.MultVector(3, First);
  167. First.ToConsoleAll();
  168. First.DivVector(2, First);
  169. First.ToConsoleAll();
  170. int Bound = length;
  171. Console.Write("Введите имя нового вектора: ");
  172. Name = Convert.ToString(Console.ReadLine());
  173. Console.Write("Введите курс нового вектора: ");
  174. Kurs = Convert.ToInt32(Console.ReadLine());
  175. Console.Write("Введите длину вектора Third: ");
  176. length = Convert.ToInt32(Console.ReadLine());
  177.  
  178. PVector Third = new PVector(Name, Kurs, length, Bound);
  179. Third.MultLength(2);
  180. Third.Metod();
  181. Console.Write("Введите индекс элемента: ");
  182. Search = Convert.ToInt32(Console.ReadLine());
  183. First.ToConsoleIndex(Search);
  184. Console.ReadKey();
  185. }
  186. }
  187. }

Решение задачи: «Помогите найти причину StackOverflowException»

textual
Листинг программы
  1. set { Length = value; }

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


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

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

10   голосов , оценка 4.5 из 5

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

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

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