Помогите найти причину StackOverflowException - C#
Формулировка задачи:
Помогите пожалуйста, написал программу, но она матерится необработанным исключением, задание такое:
Доработать задание лабораторной работы №1 использовав следующие изменения:
1. Добавить класс потомок;
2. Добавить метод реализуемый в потомке
3. Использовать в классе потомке доступ к полям базового класса
4. Добавить класс клиент в котором использовать клиентский статический и динамический ме-тод.
5. Выполнить описание добавляемых методов.
Вродебы как все сделано, но пахать она не хочет(
using System;
using System.Linq;
namespace Задание
{
class Vector
{
protected int[] items;
protected int Bound;
protected static bool test;
public Vector(int Bound, int length)
{
items = new int[length];
this.Bound = Bound;
}
public int Length
{
set { Length = value; }
get { return items.Length; }
}
public int this[int index]
{
get
{
return items[index];
}
set
{
items[index] = value;
}
}
public void SumVector(int length, Vector First, Vector Second)
{
if (First.Bound != Second.Bound || First.Length != Second.Length)
throw new InvalidOperationException();
Console.Write("Сложение: ");
for (int Count = 0; Count < Length; Count++)
{
First[Count] += Second[Count];
}
}
public void SubsVector(int length, Vector First, Vector Second)
{
if (First.Bound != Second.Bound || First.Length != Second.Length)
throw new InvalidOperationException();
Console.Write("Вычитание: ");
for (int Count = 0; Count < Length; Count++)
{
First[Count] -= Second[Count];
}
}
public void MultVector(int k, Vector First)
{
Console.Write("Умножение на скаляр: ");
for (int i = 0; i < First.Length; i++)
First.items[i] = k * First.items[i];
}
public void DivVector(int k, Vector First)
{
Console.Write("Деление: ");
for (int i = 0; i < First.Length; i++)
First.items[i] = First.items[i] / k;
}
public void ToConsoleAll()
{
Console.WriteLine(string.Join(" ", items));
}
public void ToConsoleIndex(int Search)
{
try
{
int index = Search;
Console.WriteLine("Искомый элемент: {0}", this[index]);
}
catch
{
Console.Write("Элемента по этому индексу не существует.");
}
}
public bool Test()
{
if (Bound % 2 == 0)
{
test = true;
}
else
{
test = false;
}
return test;
}
}
class client //4. класс клиент в котором использованы клиентский статический и динамический ме-тод.
{
string Name;
static int kurs;
public void Har(string Name, int Kurs)
{
this.Name = Name;
kurs = Kurs;
Console.WriteLine("\nИмя Вектора - {0}", Name);
Say_Kurs();
}
public static void Say_Kurs()
{
Console.WriteLine("Курс - {0}", kurs);
}
}
class PVector : Vector //1.класс потомок;
{
public PVector(string Name, int Kurs, int length, int Bound)
: base(length, Bound)
{
client Third = new client();
Third.Har(Name, Kurs);
}
public void Metod()
{
if (Test())
{
Console.WriteLine("Четная");
}
else
{
Console.WriteLine("Нечетная");
}
}
public void MultLength(int b)
{
Length += b;//3. Использование в классе потомке доступа к полям базового класса
Bound += b;
Console.WriteLine(" ");
}
}
class Program
{
static void Main(string[] args)
{
int length;
int Search;
string Name;
int Kurs;
Console.Write("Введите длину векторов First и Second: ");
length = Convert.ToInt32(Console.ReadLine());
Vector First = new Vector(1, length);
Vector Second = new Vector(1, length);
Random R = new Random();
Console.Write("Вектор First: ");
for (int Count = 0; Count < length; Count++)
{
First[Count] = R.Next(1, 10);
Console.Write("{0} ", First[Count]);
}
Console.ReadLine();
Console.Write("Вектор Second: ");
for (int Count = 0; Count < length; Count++)
{
Second[Count] = R.Next(-10, -1);
Console.Write("{0} ", Second[Count]);
}
Console.ReadLine();
First.SumVector(length, First, Second);
First.ToConsoleAll();
First.SubsVector(length, First, Second);
First.ToConsoleAll();
First.MultVector(3, First);
First.ToConsoleAll();
First.DivVector(2, First);
First.ToConsoleAll();
int Bound = length;
Console.Write("Введите имя нового вектора: ");
Name = Convert.ToString(Console.ReadLine());
Console.Write("Введите курс нового вектора: ");
Kurs = Convert.ToInt32(Console.ReadLine());
Console.Write("Введите длину вектора Third: ");
length = Convert.ToInt32(Console.ReadLine());
PVector Third = new PVector(Name, Kurs, length, Bound);
Third.MultLength(2);
Third.Metod();
Console.Write("Введите индекс элемента: ");
Search = Convert.ToInt32(Console.ReadLine());
First.ToConsoleIndex(Search);
Console.ReadKey();
}
}
}Решение задачи: «Помогите найти причину StackOverflowException»
textual
Листинг программы
set { Length = value; }