加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

gjy c#

发布时间:2020-12-16 01:22:46 所属栏目:百科 来源:网络整理
导读:1 using System; 2 public class MyDate{ 3 private int month,day,year; 4 public MyDate( int _month= 1 , int _day= 1 , int _year= 1900 ){ 5 bool ok= true ; 6 if (_month 12 || _month 1 || _year 0 || _day 0 ) ok= false ; 7 if (_month= 7 ( (_mon
 1 using System;
 2 public class MyDate{
 3     private int month,day,year;
 4     public MyDate(int _month=1,int _day=1,int _year=1900){
 5         bool ok=true;
 6         if(_month>12 || _month<1 || _year<0 || _day<0) ok=false;
 7         if(_month<=7 &&( (_month%2==1 && _day>31) || (_month%2==0 && _day>30) ) ) ok=false;
 8         if(_month>=8 &&( (_month%2==1 && _day>30) || (_month%2==0 && _day>31) ) ) ok=false;
 9         if(_year%4==0 && _month==2 && _day>29) ok=false;
10         if(_year%4!=0 && _month==2 && _day>28) ok=false;
11         if(!ok){
12             Console.WriteLine("invalid date");
13             this.month=1;
14             this.day=1;
15             this.year=1900;
16             return;
17         }
18         this.month=_month;
19         this.day=_day;
20         this.year=_year;
21     }
22     public void SetDate(int _month,int _day,int _year){
23         bool ok=true;
24         if(_month>12 || _month<1 || _year<0 || _day<0) ok=false;
25         if(_month<=7 &&( (_month%2==1 && _day>31) || (_month%2==0 && _day>30) ) ) ok=false;
26         if(_month>=8 &&( (_month%2==1 && _day>30) || (_month%2==0 && _day>31) ) ) ok=false;
27         if(_year%4==0 && _month==2 && _day>29) ok=false;
28         if(_year%4!=0 && _month==2 && _day>28) ok=false;
29         if(!ok){
30             Console.WriteLine("invalid date");
31             return;
32         }
33         this.month=_month;
34         this.day=_day;
35         this.year=_year;
36     }
37     public void Display(){
38         Console.WriteLine("{0}/{1}/{2}",month,year);
39     }
40 }
41 public class DateTest{
42     public static void Main(){
43         MyDate oneDate = new MyDate(2,29,1222);
44         oneDate.Display();
45         oneDate.SetDate(2,2015);
46         oneDate.Display();
47         Console.WriteLine(oneDate);
48     }
49 }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读