他们所要求的一个例子就是很棒

时间:2010-09-28 04:08:52

标签: c#

  

可能重复:
  A class definition for a date class that contains three integer data members:month,day,year

我不确定他们在这里要求什么。一个例子就是很棒。

以下是完整的要求清单。我正在阅读一本我正在阅读的书中的练习,但我已经一遍又一遍地阅读了这一章,但我不能理解它。

1.A class definition for a date class that contains three integer data members:month,day,year

2.One constructor that assigns the date 1/1/2000 to any new object that does not recieve any arguments.

3.One constructor thats accepts month and day arguements and uses a default year of 2004
4.One constructor thats accepts month, day,and year arguements
5.Each constructor should also output a message to the user stating which constructor is currently being used.
6.A method that displays the values in the date object

1 个答案:

答案 0 :(得分:1)

1

public class myDate
{
  public int day {get;set;}
  public int month {get;set;}
  public int year {get;set;}
}

2

public myDate()
{
  this.day = 1;
  this.month = 1;
  this.year = 2000;
}

3

public myDate(int day, int month)
{
  this.day = day;
  this.month = month;
  this.year = 2004;
}

4

public myDate(int day, int month, int year)
{
  this.day = day;
  this.month = month;
  this.year = year;
}

6

  public DateTime getDate()
  {
    return new DateTime(this.year, this.month, this.day);
  }