我是 C# 的初学者并编写了一些代码。但在那里出错。错误是:无法将类型字符串隐式转换为 System.date.time 但我在这里看到我在字符串中声明
public partial class HDate
{
private string StartYear;
public string StartYear1
{
get { return StartYear; }
set { StartYear = value; }
}
private string EndYear;
public string EndYear1
{
get { return EndYear; }
set { EndYear = value; }
}
private string Year;
public string Year1
{
get { return Year; }
set { Year = value; }
}
private DateTime StartDate;
public DateTime StartDate1
{
get { return StartDate; }
set { StartDate = value; }
}
private DateTime EndDate;
public DateTime EndDate1
{
get { return EndDate; }
set { EndDate = value; }
}
private string StartMonth;
public string StartMonth1
{
get { return StartMonth; }
set { StartMonth = value; }
}
private string EndMonth;
public string EndMonth1
{
get { return EndMonth; }
set { EndMonth = value; }
}
private DateTime StartDay;
public DateTime StartDay1
{
get { return StartDay; }
set { StartDay = value; }
}
private DateTime EndDay;
public DateTime EndDay1
{
get { return EndDay; }
set { EndDay = value; }
}
public HDate() { }
public HDate(){
DateTime today = DateTime.Now;
int year = today.Year;
int month = today.Month;
DateTime day = today;
DateTime StartDate = (StartYear + StartMonth + StartDay);
DateTime EndDate = (EndYear + EndMonth + EndDay);
if (month <= 6)
{
//string StartYear = Convert.ToString(year-1);
string StartYear = (year - 1).ToString();
string StartMonth = Convert.ToString(7);
string EndYear = Convert.ToString(year);
string EndMonth = Convert.ToString(6);
string EndDay = Convert.ToString(30);
}
else if(month >= 7)
{
string StartYear =Convert.ToString(year);
string StartMonth = Convert.ToString(7);
string StartDay = Convert.ToString(1);
string EndYear = Convert.ToString(year+1);
string EndMonth = Convert.ToString(6);
string EndDay = Convert.ToString(30);
}
return StartDate+';'+EndDate;
}
这些数据将其返回到另一个函数..