using System;
using System.Windows.Forms;class compositionTest
{
static void Main(string[] args)
{
Employee e = new Employee("Bob", "Jones", 7, 24, 1949, 3, 12, 1988);//这里是实例化一个对象吧
MessageBox.Show(e.ToemployessString(),"Testing Class Employee");
}
}public class Employee
{
private string firstName;
private string lastName;
private Date birthDate;
private Date hireDate; public Employee(string first,string last,
int birthMonth,int birthDay,int birthYear,
int hireMonth,int hireDay,int hireYear)
{
firstName = first;
lastName = last;
//下面这两个也是实例化两个对象吗?如果是的话改成Date birthDate = new Date(birthMonth, birthDay, birthYear);,在下面的hireDate.ToDateString()就提示错误。为什么?而上面的则可以这样啊。。
birthDate = new Date(birthMonth, birthDay, birthYear);
hireDate = new Date(hireMonth, hireDay, hireYear);
} public string ToemployessString()
{
return lastName + ", " + firstName +
" Hired: " + hireDate.ToDateString() +
" BirthDay:" + birthDate.ToDateString();
}
}public class Date
{
private int Month;
private int Day;
private int Year; public Date(int theMonth,int theDay,int theYear)
{
if (theMonth > 0 && theMonth <= 12)
Month = theMonth;
else
{
theMonth = 1;
Console.WriteLine("Month {0} invalid.Set to month 1.", +theMonth);
}
Year=theYear;
Day = checkDay(theDay);
} public int checkDay(int testDay)
{
int[] dayperMonth ={ 0,31,28,31,30,31,30,31,31,30,31,30,31}; if (testDay > 0 && testDay <= dayperMonth[Month])
return testDay;
if (Month == 2 && testDay == 29 &&
(Year % 400 == 0 || Year % 4 == 0 && Year % 100 != 0))
return testDay; Console.WriteLine("Day (0) invalid.Set to day 1.",testDay); return 1;
} public string ToDateString()
{
return Month + "/" + Day + "/" + Year;
}
}help me~~
[email protected]
using System.Windows.Forms;class compositionTest
{
static void Main(string[] args)
{
Employee e = new Employee("Bob", "Jones", 7, 24, 1949, 3, 12, 1988);//这里是实例化一个对象吧
MessageBox.Show(e.ToemployessString(),"Testing Class Employee");
}
}public class Employee
{
private string firstName;
private string lastName;
private Date birthDate;
private Date hireDate; public Employee(string first,string last,
int birthMonth,int birthDay,int birthYear,
int hireMonth,int hireDay,int hireYear)
{
firstName = first;
lastName = last;
//下面这两个也是实例化两个对象吗?如果是的话改成Date birthDate = new Date(birthMonth, birthDay, birthYear);,在下面的hireDate.ToDateString()就提示错误。为什么?而上面的则可以这样啊。。
birthDate = new Date(birthMonth, birthDay, birthYear);
hireDate = new Date(hireMonth, hireDay, hireYear);
} public string ToemployessString()
{
return lastName + ", " + firstName +
" Hired: " + hireDate.ToDateString() +
" BirthDay:" + birthDate.ToDateString();
}
}public class Date
{
private int Month;
private int Day;
private int Year; public Date(int theMonth,int theDay,int theYear)
{
if (theMonth > 0 && theMonth <= 12)
Month = theMonth;
else
{
theMonth = 1;
Console.WriteLine("Month {0} invalid.Set to month 1.", +theMonth);
}
Year=theYear;
Day = checkDay(theDay);
} public int checkDay(int testDay)
{
int[] dayperMonth ={ 0,31,28,31,30,31,30,31,31,30,31,30,31}; if (testDay > 0 && testDay <= dayperMonth[Month])
return testDay;
if (Month == 2 && testDay == 29 &&
(Year % 400 == 0 || Year % 4 == 0 && Year % 100 != 0))
return testDay; Console.WriteLine("Day (0) invalid.Set to day 1.",testDay); return 1;
} public string ToDateString()
{
return Month + "/" + Day + "/" + Year;
}
}help me~~
[email protected]
解决方案 »
- C#中String.Empty、NULL与""三者的区别是什么?
- SQL中image的长度
- 在点击DataGridView的列进行排序时候的问题
- C# DataGridView 的问题 急!!
- c#如何获取当前正在IE中游览网页的源文件
- 高分求解“传值问题”
- 在VS中测试一切正常,但是部署到IIS上就出现了一下错误。请高手们帮忙看看是那的问题
- 测序发布问题
- 请问怎样才能利用C#自动从Windows2000的机器上获取机器内已装的ODBC数据源的内容?
- 在C#应用程序中如何实现:1、断开网络连接 2、重新启动计算机
- C#中Container有何作用
- 这里有一个求解80个皇后的程序,找到解平均需要200毫秒。但是有点bug?
对呀
是的如果是的话改成Date birthDate = new Date(birthMonth, birthDay, birthYear);,
改成这样就定义了一个新的局部变量birthDate,当然会出错了
在下面的hireDate.ToDateString()就提示错误。为什么?而上面的则可以这样啊。。
birthDate = new Date(birthMonth, birthDay, birthYear);
hireDate = new Date(hireMonth, hireDay, hireYear);
}