【发布时间】:2014-09-02 19:26:27
【问题描述】:
我在 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; }
}
但是当我尝试使用这样定义的函数时:
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";
发生堆栈溢出 :) 你能帮我解决这个问题吗?
【问题讨论】:
-
请注意,这与
DateTime无关。这是您的 setter 的一个简单问题,可以通过使用更好的命名约定来避免。
标签: c# properties setter