问题描述
如果我将此项目添加到顶部,所有错误都会消失,但是.exe实际上不会执行任何操作.
If I add this top my project all errors go away, but the .exe doesn't actually do anything.
[STAThread]
静态void Main()
{
}
[STAThread]
static void Main()
{
}
如果我取出来并使用它:
If I take that out and use this:
private void Main(string [] args)
{
DateTime dt = DateTime.Today.AddDays(-1);
字符串日期= String.Format(" {0:yyyyMMdd},dt);
getFTPFile("raw_CA _" +日期+".txt");
getFTPFile("raw_EM _" +日期+".txt");
getFTPFile("raw_GLB _" +日期+".txt");
getFTPFile("raw_US _" +日期+".txt");
}
private void Main(string[] args)
{
DateTime dt = DateTime.Today.AddDays(-1);
string date = String.Format("{0:yyyyMMdd}", dt);
getFTPFile("raw_CA_" + date + ".txt");
getFTPFile("raw_EM_" + date + ".txt");
getFTPFile("raw_GLB_" + date + ".txt");
getFTPFile("raw_US_" + date + ".txt");
}
然后我收到以下错误消息.
Then I get the following error.
ConsoleApplication1.exe"不包含适用于入口点的静态"Main"方法. ConsoleApplication1
ConsoleApplication1.exe' does not contain a static 'Main' method suitable for an entry point ConsoleApplication1
最后,如果我将其设置为静态,就像这样.
Finally, if I make it static, like this.
static void Main(string [] args)
{
DateTime dt = DateTime.Today.AddDays(-1);
字符串日期= String.Format("{{:yyyyMMdd}",dt);
getFTPFile("raw_CA _" +日期+".txt");
getFTPFile("raw_EM _" +日期+".txt");
getFTPFile("raw_GLB _" +日期+".txt");
getFTPFile("raw_US _" +日期+".txt");
}
static void Main(string[] args)
{
DateTime dt = DateTime.Today.AddDays(-1);
string date = String.Format("{0:yyyyMMdd}", dt);
getFTPFile("raw_CA_" + date + ".txt");
getFTPFile("raw_EM_" + date + ".txt");
getFTPFile("raw_GLB_" + date + ".txt");
getFTPFile("raw_US_" + date + ".txt");
}
非静态字段,方法或属性'ConsoleApplication1.Program.getFTPFile(string)'需要对象引用
An object reference is required for the non-static field, method, or property 'ConsoleApplication1.Program.getFTPFile(string)'
最后,我想到了这个.
public static void Main(string [] args)
{
DateTime dt = DateTime.Today.AddDays(-1);
字符串日期= String.Format(" {0:yyyyMMdd},dt);
程序p = new Program();
p.getFTPFile("raw_CA_" +日期+".txt");
p.getFTPFile("raw_EM _" +日期+".txt");
p.getFTPFile("raw_GLB _" +日期+".txt");
p.getFTPFile("raw_US_" +日期+".txt");
}
public static void Main(string[] args)
{
DateTime dt = DateTime.Today.AddDays(-1);
string date = String.Format("{0:yyyyMMdd}", dt);
Program p = new Program();
p.getFTPFile("raw_CA_" + date + ".txt");
p.getFTPFile("raw_EM_" + date + ".txt");
p.getFTPFile("raw_GLB_" + date + ".txt");
p.getFTPFile("raw_US_" + date + ".txt");
}
现在,所有编译错误都消失了,但是出现了运行时错误.有人可以在这里解释我在做什么错吗?
Now, all compile errors are gone, but there is a run-time error. Can someone please explain what I'm doing wrong here?
知识是我唯一可以给您的东西,并且仍然保留下来,我们俩对此都比较满意.
Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.
推荐答案
示例:
static void Main(params string[] args)
{
if (args.Any())
{
// Do code that references args
}
else
{
// Do code that depends on no input arguments.
}
}
这篇关于不同的主要入口点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!