【发布时间】:2013-07-17 12:34:39
【问题描述】:
我有以下超类:
abstract class ContactQueue
{
public abstract DateTime period {
get; set; }
public abstract String type { get; set; }
public abstract String toString();
public String ReWritePeriod(String choice)
{
new CultureInfo("da-DA");
switch (choice)
{
case ("Day"):
return period.ToString("ddd");
case ("Week"):
return ""+period.ToString("ddd")+" Uge: "+weekNumber(period);
case ("Year"):
return period.Year.ToString();
default:
return "";
}
}
private int weekNumber(DateTime fromDate)
{
// Get jan 1st of the year
DateTime startOfYear = fromDate.AddDays(-fromDate.Day + 1).AddMonths(-fromDate.Month + 1);
// Get dec 31st of the year
DateTime endOfYear = startOfYear.AddYears(1).AddDays(-1);
// ISO 8601 weeks start with Monday
// The first week of a year includes the first Thursday
// DayOfWeek returns 0 for sunday up to 6 for saterday
int[] iso8601Correction = { 6, 7, 8, 9, 10, 4, 5 };
int nds = fromDate.Subtract(startOfYear).Days + iso8601Correction[(int)startOfYear.DayOfWeek];
int wk = nds / 7;
switch (wk)
{
case 0:
// Return weeknumber of dec 31st of the previous year
return weekNumber(startOfYear.AddDays(-1));
case 53:
// If dec 31st falls before thursday it is week 01 of next year
if (endOfYear.DayOfWeek < DayOfWeek.Thursday)
return 1;
else
return wk;
default: return wk;
}
}
}
我有以下类继承了上面的类:
class Callback : ContactQueue
{
public int completedCallbacks{get; set;}
public int completed_within_timeframe{get; set;}
public int answerPercentage { get; set; }
public override String type {get; set;}
public override DateTime period { get; set; }
public Callback(String type,DateTime period)
{
this.type = type;
this.period = period;
}
public override String toString()
{
return type;
}
}
现在我想测试我的继承方法是否真的有效,所以我做了以下操作:
Callback cb = new Callback("Callback",start);
MessageBox.Show(cb.ReWritePeriod("Day"));
然后我的程序抛出一个错误!
我做错了什么?
错误信息
The invocation of the constructor on type 'Henvendelser.MainWindow' that matches the specified binding constraints threw an exception.
【问题讨论】:
-
错误是...?它发生在哪条线上……?一旦你通过调试器运行它并验证了你的信息,你怀疑问题的大致范围是......?
-
我已经用错误更新了我的帖子!
-
听起来几乎是无关的。如果删除
MessageBox会发生什么?打电话cb.ReWritePeriod("Day")不举报?编辑:这与您问here 的问题有关系吗?
标签: c# inheritance polymorphism