继承方法抛出错误

时间:2013-07-17 12:34:39

标签: c# inheritance polymorphism

我有以下超级课程:

   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.

1 个答案:

答案 0 :(得分:2)

似乎错误(和异常的原因)在行

  new CultureInfo("da-DA");

没有这样的文化“da-DA”。你的意思是“de-DE”(德国)还是“da-DK”(丹麦)?

相关问题