如果直接用:this._birthday = value ; 如果为空时就会出错。要怎么写好呢?
我暂时这样写的,感觉不对劲 private DateTime _birthday;
/// <summary>
/// 出生日期
/// </summary>
public DateTime Birthday
{
get {return this._birthday;}
set {
try
{
this._birthday =DateTime.Parse(value);
}
catch
{}
}
}还有int 形式的。如果空为是设为什么呢?不明白呢。
我暂时这样写的,感觉不对劲 private DateTime _birthday;
/// <summary>
/// 出生日期
/// </summary>
public DateTime Birthday
{
get {return this._birthday;}
set {
try
{
this._birthday =DateTime.Parse(value);
}
catch
{}
}
}还有int 形式的。如果空为是设为什么呢?不明白呢。
this._birthday =DateTime.Parse(value);
运算符“==”无法应用于“System.DateTime”和“string”类型的操作数
无法将 NULL 转换成“System.DateTime”,因为它是一种数值类型
这样是运行时错误:XXXX.Birthday = (DateTime) obj;//设obj == null。
装箱方案:object Birthday
{
set
{
if ( value == null )
_birthdaynull = true;
else
_birthday = (DateTime) value;
}
}或者期待C# 2.0中的
DateTime?
this._birthday =DateTime.MinValue;同意 ffjing(猪头不卖)
{
set
{
if ( value == null || value is DateTime )
_birthday = value;
}
}