我有一个这样的 php 代码,我需要将其转换为 .NET
function jaktDate2()
{
Global $nameofselectbox,$startYear,$endYear,$year,
$startDate,$endDate,$startMounth,$endMounth,$startDay,$endDay;
$today = getdate();
$year=$today['year'];
$mounth=$today['mon'];
$day=$today['mday'];
//$year="2004";
//$mounth="7";
//$day="1";
if(round($mounth)<="6"){$startYear=$year-1;$startMounth="-07";$startDay="-01";
$endYear=$year;$endMounth="-06";$endDay="-30";}
elseif(round($mounth)>="7"){$startYear=$year;$startMounth="-07";$startDay="-01";
$endYear=$year+1;$endMounth="-06";$endDay="-30";}
$startDate=$startYear.$startMounth.$startDay;
$endDate=$endYear.$endMounth.$endDay;
return $startDate.";".$endDate;
}
这是我的转换:
public class HuntingDate
{
public string StartYear;
public string EndYear;
public string Year;
public DateTime StartDate;
public DateTime EndDate;
public string StartMonth;
public string EndMonth;
public DateTime StartDay;
public DateTime EndDay;
private string _startYear;
public string StartYear
{
get { return _startYear;}
set { _startYear = value;}
}
private string _endYear;
public string EndYear
{
get{return _endYear;}
set { _endYear = value; }
}
private DateTime _startDate;
public DateTime StartDate
{
get { return _startDate;}
set { _startDate = value;}
}
private DateTime _endDate;
public DateTime EndDate
{
get { return _endDate;}
set { _startDate = value;}
}
private string _year;
public string Year
{
get { return _year;}
set { _year = value;}
}
private string _startMonth;
public string StartMonth
{
get { return _startMonth;}
set { _startMonth = value;}
}
private string _endMonth;
public string EndMonth
{
get { return _endMonth;}
set { _endMonth = value;}
}
private DateTime _startDay;
public DateTime StartDay
{
get { return _startDay;}
set { _startDay = value;}
}
private DateTime _endDay;
public DateTime EndDay
{
get { return _endDay; }
set { _endDay = value; }
}
public HuntingDate(){
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);
}
}
}
}
我在这里发现的问题:
DateTime StartDate = (StartYear+StartMonth+StartDay);
DateTime EndDate = (EndYear+EndMonth+EndDay);
问题是:这个成员被定义了不止一次
在这里红色下划线的 startyear startmonth startday & 以及其他部分。