C# 提供了一种更加便捷、简单而又直接的属性访问方式。上述代码改成:
1. usingSystem;
2. classDate
3. {
4. publicintDay{
5. get{
6. returnday;
7. }
8. set{
9. day=value;
10. }
11. }
12. intday;
13.
14. publicintMonth{
15. get{
16. returnmonth;
17. }
18. set{
19. month=value;
20. }
21. }
22. intmonth;
23.
24. publicintYear{
25. get{
26. returnyear;
27. }
28. set{
29. year=value;
30. }
31. }
32. intyear;
33.
34. publicboolIsLeapYear(intyear)
35. {
36. returnyear%4==0?true:false;
37. }
38. publicvoidSetDate(intday,intmonth,intyear)
39. {
40. this.day=day;
41. this.month=month;
42. this.year=year;