StackOverflowException в свойствах - C#
Формулировка задачи:
Здравствуйте!
Возник вопрос:не очень понимаю в честь чего в моем свойстве Price при установлении значения выпадает StackOverflow.
Текст ошибки таков:An unhandled exception of type 'System.StackOverflowException'
Сама ошибка выбивается на 15 строке
public abstract class Vehicle
{
protected double CoordinateX, CoordinateY, speed;
public string Name { get; set; }
public string Mark { get; set; }
public uint MadeYear { get; set; }
public double Price
{
get
{
return Price;
}
set
{
Price = value;
}
}
public void SetCoordinate(double CoordinateX, double CoordinateY)
{
this.CoordinateX = CoordinateX;
this.CoordinateY = CoordinateY;
}
public double GetCoordinateX() { return CoordinateX; }
public double GetCoordinateY() { return CoordinateY; }
public void SetSpeed(double speed)
{
if (speed < 0)
throw new Exception("Speed value in Vehicle class must be greater than or equal to zero");
this.speed = speed;
}
public double GetSpeed() { return speed; }
protected Vehicle(string name, double speed, string mark, uint madeYear, double price)
{
Price = price;
MadeYear = madeYear;
Mark = mark;
this.speed = speed;
Name = name;
}
protected Vehicle()
: this(null, 0, null, (uint)DateTime.Today.Year, 0) { }
}
Поторопился с вопросом.Там же нужно было поле создать для хранения вводимого значения.
Решение задачи: «StackOverflowException в свойствах»
textual
Листинг программы
private double _price;
public double Price
{
get
{
return _price;
}
set
{
_price = value;
}
}