我现在开始将我的代码组织到单独的 .cs 文件中,为了让与 UI 一起工作的方法继续这样做,我将在相同的命名空间和公共(public)部分类名下创建 .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 应用程序)我收到此错误消息:
Does not contain a static 'main' method suitable for an entry point
我查看了 Application->Startup 对象中的应用程序属性,但它没有提供任何选项。我如何通知应用程序从具有我的 InitializeComponent(); 的 .cs 文件开始?命令?
- 到目前为止,我环顾四周都没有找到解决方案。
- 每个 .cs 文件的属性都设置为“编译”。
- 我在解决方案资源管理器中没有看到 App.xaml 文件,但看到了 app.config 文件。
我还是个新手,这是我第一次尝试使用 C# 代码组织方法。
最佳答案
我也在研究这个问题,就我而言,解决方案太简单了。我在解决方案中添加了一个新的空项目。新添加的项目会自动设置为控制台应用程序。但由于添加的项目是一个“空”项目,因此该新项目中不存在 Program.cs。 (如预期的那样)
我需要做的就是将项目属性的输出类型更改为类库
关于c# - 不包含适合入口点的静态 'main' 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9607702/