0

我的代码是 -

public partial class App : Application
{

    HarvestApp.GoogleAPIManager GAPImanager = new HarvestApp.GoogleAPIManager();

    List<Event>todayCalendar = GAPImanager.GetCalendarEventsForDate(DateTime.Today);

    HarvestApp.HarvestManager HAPIManager = new HarvestApp.HarvestManager();

    Console.WriteLine("Entries found for Today :" + todayCalendar.Count);

    foreach(Event todayEvent in todayCalendar)
    {
        var addEvent = new HarvestApp.Harvest_TimeSheetEntry(todayEvent);
        EntryList.Add(addEvent);
        HAPIManager.postHarvestEntry(addEvent);
    }

 }

它给了我令牌错误。请帮忙。

4

2 回答 2

11

问题是您确实将代码直接放在类中,而不是像构造函数那样的成员中:

public partial class App : Application
{
    public App()
    {
        HarvestApp.GoogleAPIManager GAPImanager = new HarvestApp.GoogleAPIManager();

        List<Event>todayCalendar = GAPImanager.GetCalendarEventsForDate(DateTime.Today);

        HarvestApp.HarvestManager HAPIManager = new HarvestApp.HarvestManager();

        Console.WriteLine("Entries found for Today :" + todayCalendar.Count);

        foreach(Event todayEvent in todayCalendar)
        {
            var addEvent = new HarvestApp.Harvest_TimeSheetEntry(todayEvent);
            EntryList.Add(addEvent);
            HAPIManager.postHarvestEntry(addEvent);
        }
    }
 }
于 2013-05-14T07:43:10.780 回答
1

您不能声明代码指令,例如:

Console.WriteLine("Entries found for Today :" + todayCalendar.Count);

foreach(Event todayEvent in todayCalendar)
{
    var addEvent = new HarvestApp.Harvest_TimeSheetEntry(todayEvent);
    EntryList.Add(addEvent);
    HAPIManager.postHarvestEntry(addEvent);
}

在你的班级里。

您应该在构造函数或特定方法中进行这些调用。

于 2013-05-14T07:43:50.220 回答