C#日期成了0001-1-1
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace Property
{
class Program
{
static void Main(string[] args)
{
User us = new User();
us.Name= "张三 ";
us.Sex= "提 ";
us.BrithDay = Convert.ToDateTime( "1980-01-01 ");
Console.WriteLine(us.BrithDay);
Console.WriteLine( "姓名: " + us.Name+ " 性别: " + us.Sex+ " 年龄 "+us.Age);
}
}
class User
{
private string m_Name;
private string m_Sex;
private DateTime m_BrithDay;
public DateTime BrithDay
{
set
{
if (value < Convert.ToDateTime( "1900-1-1 ") || value.Year > DateTime.Now.Year - 3)
{
MessageBox.Show( "用户年龄非法 ");
}
}
get
{
return m_BrithDay;
}