【Csharp】输入年和月份,输出本月有几天
1 题目描述:输入年和月份,输出本月有几天
输入年和月份,输出本月有几天(窗体控制)
2 源码详解
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Csharp1_2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int year, month;
year = Convert.ToInt32(textBox_year.Text);
month = Convert.ToInt32(textBox_month.Text);
if ( month == 1 )
{
res.Text = "31";
}
else if ( month == 3 )
{
res.Text = "31";
}
else if ( month == 5 )
{
res.Text = "31";
}
else if ( month == 7 )
{
res.Text = "31";
}
else if ( month == 8 )
{
res.Text = "31";
}
else if ( month == 10 )
{
res.Text = "31";
}
else if ( month == 12 )
{
res.Text = "31";
}
else if ( month == 4 )
{
res.Text = "30";
}
else if ( month == 6 )
{
res.Text = "30";
}
else if ( month == 9 )
{
res.Text = "30";
}
else if ( month == 11 )
{
res.Text = "30";
}
else if ( month == 2 )
{
if ( year % 400 == 0 )
{
res.Text = "29";
}
else if ( year % 100 == 0 )
{
res.Text = "29";
}
else if ( year % 4 == 0 )
{
res.Text = "29";
}
else
{
res.Text = "28";
}
}
}
}
}