9.7. Exercises

  1. Suppose you are adding the following data items as properties to a class. How would you write them in the class?

    1. A person's last name

    2. A zip code

    3. The days of the week

  2. Suppose you want to add a general method to the clsDates class that returns the number of days in a given month. How would you write the code?

  3. Give a good example of where you would use the public access specifier to define a class property.

  4. Modify the following SOC code to use an if statement instead:

    lblLeapYearResult.Text = year.ToString() + " is " +
               ((leap == 1)? "":"not ") + "a leap year";

    Which form would you use in your own code and why?

  5. Suppose you overload the clsDates constructor so that the following constructor is available. Would you modify your getLeapYear() method and, if so, how?

    public clsDates(int yr)
    {
        year = yr;
    }

Get Beginning C# 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.