属性设置器上的堆栈溢出

0 c# setter properties

我在C#中有一个具有当前属性的对象.

public DateTime startDate
{
    get 
    {
        string[] ymd = Environment.GetCommandLineArgs()[2].Split('.');
        return new DateTime(Int32.Parse(ymd[2]), Int32.Parse(ymd[1]), Int32.Parse(ymd[0])); 
    }
    set { startDate = value; }
}
Run Code Online (Sandbox Code Playgroud)

但是当我尝试使用定义为此的函数时:

public String Calculate(){
    if (startDate > endDate)
        return "not calculable since the end date can not be before than the start date.";

    while (startDate <= endDate)
    {
        if (startDate.DayOfWeek.ToString()[0] != 'S')
            count++;
        startDate = startDate.AddDays(1);
    }

    return "not implemented yet";
Run Code Online (Sandbox Code Playgroud)

Stack Overflow发生:)你可以帮我解决这个问题吗?

Eld*_*iev 7

你的二传手有一个错误.您正在尝试分配给同一个属性,这是堆栈溢出的原因,因为对属性的每个赋值都只是调用它的setter.

set { startDate = value; }
Run Code Online (Sandbox Code Playgroud)