private DateTime submittime = Convert.ToDateTime(DateTime.Now.ToShortDateString();
初始化部分
public string SubmitTime
{
get { return submittime; }
set { submittime = value; }
}
运行程序是报错: 无法将类型“System.DateTime”隐式转换为“string”
无法将类型“string”隐式转换为“System.DataTime”
11 个解决方案
#1
日期变量.ToString()
DateTime.Parse(字符串变量)
DateTime.Parse(字符串变量)
#2
public string SubmitTime
{
get { return submittime。ToString(); }
set { submittime = DateTime.Parse(value); }
}
类型一致
{
get { return submittime。ToString(); }
set { submittime = DateTime.Parse(value); }
}
类型一致
#3
public string SubmitTime
{
get { return submittime.ToString(); }
set { submittime =Convert.ToDateTime(value); }
}
{
get { return submittime.ToString(); }
set { submittime =Convert.ToDateTime(value); }
}
#4
为什么我没有问题,,,,
#5
public
DateTime SubmitTime
#6
public DateTime SubmitTime
{
get { return submittime; }
set { submittime = value; }
}
{
get { return submittime; }
set { submittime = value; }
}
#7
。。。明显不对嘛
#8
两边类型不一样,当然不行啦
#9
1.return submittime.
ToString();
或者
2.public DateTime SubmitTime
或者
2.public DateTime SubmitTime
#10
yEs
#11
问题解决了。。。谢谢大家咯!!
#1
日期变量.ToString()
DateTime.Parse(字符串变量)
DateTime.Parse(字符串变量)
#2
public string SubmitTime
{
get { return submittime。ToString(); }
set { submittime = DateTime.Parse(value); }
}
类型一致
{
get { return submittime。ToString(); }
set { submittime = DateTime.Parse(value); }
}
类型一致
#3
public string SubmitTime
{
get { return submittime.ToString(); }
set { submittime =Convert.ToDateTime(value); }
}
{
get { return submittime.ToString(); }
set { submittime =Convert.ToDateTime(value); }
}
#4
为什么我没有问题,,,,
#5
public
DateTime SubmitTime
#6
public DateTime SubmitTime
{
get { return submittime; }
set { submittime = value; }
}
{
get { return submittime; }
set { submittime = value; }
}
#7
。。。明显不对嘛
#8
两边类型不一样,当然不行啦
#9
1.return submittime.
ToString();
或者
2.public DateTime SubmitTime
或者
2.public DateTime SubmitTime
#10
yEs
#11
问题解决了。。。谢谢大家咯!!