Which style of defaulting do you prefer?

    /* ====================  Style A ==================== */
    class PersonA
    {
        string first;
        string last;
        int    age;

        PersonA(string first)              : this(first, null, -1) {}
        PersonA(string first, string last) : this(first, last, -1) {}
        PersonA(string first, string last, int age)
        {
            if (last == null) last = "Smith";
            if (age  <  0   ) age = 30;

            // do the work
        }
    }

    /* ====================  Style B ==================== */
    class PersonB
    {
        string first;
        string last;
        int    age;

        PersonB(string first)              : this(first, "Smith", 30) {}
        PersonB(string first, string last) : this(first, last   , 30) {}
        PersonB(string first, string last, int age)
        {
            // do the work
        }
    }

Cheers...David

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to