【发布时间】:2012-03-07 19:20:44
【问题描述】:
我开始将我的代码组织到单独的 .cs 文件中,并且为了允许与 UI 一起使用的方法继续这样做,我将在相同的命名空间和公共部分类名下创建 .cs 代码,所以这些方法可以互操作。
我的头在四个文件中看起来像这样,包括我的主要核心文件调用:
public shell()
{
InitializeComponent();
}
与 UI 配合使用的 .cs 文件的标头区域(并且似乎导致了这个新的冲突):
using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
using System.Data.SqlServerCe;
using System.Diagnostics;
using System.Threading;
using System.Collections.Specialized;
using System.Net;
using System.Runtime.InteropServices;
using watin = WatiN.Core;
using WatiN.Core.Native.InternetExplorer;
using System.Web;
namespace WindowsFormsApplication1
{
public partial class shell : Form
{
现在,当我尝试调试/预览我的应用程序(顺便说一句,这是 Visual Studio 2010 Express 中的 Windows 应用程序)时,我收到以下错误消息:
不包含适合入口点的静态“main”方法
我在 Application->Startup 对象中查看了应用程序属性,但它没有提供任何选项。如何通知应用程序从具有我的 InitializeComponent() 的 .cs 文件开始;命令?
- 到目前为止,我环顾四周,没有找到解决办法。
- 每个 .cs 文件的属性都设置为“编译”。
- 我在解决方案资源管理器中没有看到 App.xaml 文件,但我看到了 app.config 文件。
我还是个新手,这是我第一次尝试用 c# 代码组织方法。
【问题讨论】:
-
你有main方法吗??
-
老实说,我在代码中的任何地方都没有看到名为 Main 的方法。我也已经在这个项目上工作了几个月了。
-
您需要一个名为
main的静态方法,并具有正确的签名。这就是编译器知道如何启动程序的方式。 -
尝试在您的项目中添加类似的内容
[STAThread] static void Main(string[] args) { Application.Run(new shell()); } -
@L.B:将其创建为答案,以便他接受。
标签: c# visual-studio-2010