源代码
如下:
//-----------------------------------------------
// CsDateProperties.cs
//-----------------------------------------------
using ystem;
class CsDateProperties
{
public static void Main()
{
Date mydate = newDate();
try
{
mydate.Month = 8;
mydate.Day = 29;
mydate.Year = 2001;
Console.WriteLine("Day of year = {0}", mydate.DayOfYear);
}
catch (Exceptionexc)
{
Console.WriteLine(exc);
}
}
}
class Date
{
// Fields字段
int year;
int month;
int day;
static int[] MonthDays = new int[]{
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
// Properties属性
public int Year
{
set
{
if (value < 1600)
thrownewArgumentOutOfRangeException("Year");