错误 - C# 中的类结构或接口成员声明中的无效标记 '('
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16537564/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error - invalid token '(' in class struct or interface member declaration in c#
提问by user2380428
My code is -
我的代码是 -
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);
}
}
It gives me token error. Please help.
它给了我令牌错误。请帮忙。
回答by Daniel Hilgarth
The problem is that you did put your code directly in the class and not inside a member like a constructor:
问题是您确实将代码直接放在类中,而不是像构造函数这样的成员中:
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);
}
}
}
回答by LittleSweetSeas
You can't declare code instructions like:
您不能声明如下代码指令:
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);
}
in your class body.
在您的班级机构中。
You should make these calls in a constructor, or a specific method.
您应该在构造函数或特定方法中进行这些调用。

