我正在为我的手机开发一个应用程序,您可以在其中查看公交车时间,您可以在列表框中输入时间,然后它会检查列表,然后向您显示最接近它的时间或完全匹配的时间。我已经尝试过自己并且对我在这里找到的一些代码非常幸运,但我仍然无法让它工作。
这里
public MainPage()
{
InitializeComponent();
List<string> thedates = new List<string>();
thedates.Add("0130");
thedates.Add("0230");
thedates.Add("0330");
thedates.Add("0430");
thedates.Add("0530");
DateTime fileDate, closestDate;
int min = int.MaxValue;
foreach (DateTime date in theDates)
if (Math.Abs(date.Ticks - fileDate.Ticks) < min)
{
min = date.Ticks - fileDate.Ticks;
closestDate = date;
}
}
错误:当前上下文中不存在名称“theDates”。
对不起,如果这是简单或复杂的事情。任何帮助表示赞赏。