所以我是完全新的而不是c#,我没有想法试试这个.我花了几个小时研究,但还没有找到解决方案.
我的问题是函数getUpcomingDates():如何将变量声明myDates为getAllDates方法返回的相同数据类型?
我试过的方法之一是:MyDate[] myDates = new getAllDates();但是我在getAllDates下面得到一条红线说:"这是一种方法,但用作类型."
这样做的正确方法是什么?
[WebMethod]
private MyDate[] getAllDates()
{
System.Collections.ArrayList myDates = new System.Collections.ArrayList();
MyDate thisDate;
thisDate = new MyDate(DateTime.Parse("9/1/2011"),
"Get classes ready", "Begin of fall semester");
myDates.Add(thisDate);
thisDate = new MyDate(DateTime.Parse("1/1/2011"),
"New Year", "Happy 2011!");
myDates.Add(thisDate);
thisDate = new MyDate(DateTime.Parse("12/16/2011"),
"BUS ADM 531 Final Exam", "See study guide on course Web pages");
myDates.Add(thisDate);
return (MyDate[])myDates.ToArray(typeof(MyDate));
}
[WebMethod]
private MyDate[] getUpcomingDates()
{
MyDate[] myDates = new getAllDates();
System.Collections.ArrayList upcomingDates = new System.Collections.ArrayList();
foreach (MyDate thisDate in myDates)
{
if (thisDate.CalendarDate > DateTime.Now)
{
//date is upcoming, add to output list of dates
upcomingDates.Add(thisDate);
}
else
{
//not an upcoming date, do not add to output list
}
return (MyDate[])upcomingDates.ToArray(typeof(MyDate));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
90 次 |
| 最近记录: |