This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this questionI get this error when running my application:
Error 2 开发者_开发问答Cannot implicitly convert type 'object' to 'System.DateTime'. An explicit conversion exists (are you missing a cast?)
The code:
public object BirthDate
{
get { return date_ofbirth; }
set { date_ofbirth = value; }
}
Looks like the variable date_ofbirth
is defined as DateTime
and the property wrapper BirthDate
is marked as return/accept object
.
Change:
public object BirthDate
{
get { return date_ofbirth; }
set { date_ofbirth = value; }
}
to
public DateTime BirthDate
{
get { return date_ofbirth; }
set { date_ofbirth = value; }
}
It's not clear from the code you've given what your doing with BirthDate
but from the exception given it looks like you need it to be a DateTime
object. E.g...
public DateTime BirthDate { get {} set {} }
If this isn't what you want let us know what you are trying to do.
you are either going to have to change the property BirthDate to be a System.DateTime or cast:
DateTime myDate = (DateTime)BirthDate;
精彩评论