【发布时间】:2012-03-27 15:34:56
【问题描述】:
我尝试过(我的第一个)C# 程序:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("hello");
Console.ReadLine();
}
}
}
这很好,但如果我尝试使用 System.Windows.Forms:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("hello");
System.MessageBox("hello");
Console.ReadLine();
}
}
}
这是我得到的错误:
Error 1 The type or namespace name 'Windows' does not exist in the namespace 'System' (are you missing an assembly reference?) C:\Users\Ramy\Documents\Visual Studio 2010\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs 5 14 ConsoleApplication1
一些细节: - 我正在使用 Visual Studio 2012; - 我已经安装了 .NET 开发工具包; - 这是一个控制台应用程序。
可能是因为在控制台应用程序上无法使用 System.Windows.Forms? 如果是这样,应该是什么程序?我也尝试过使用表单,但我只显示一个窗口,没有代码。
【问题讨论】:
-
有时错误消息实际上会告诉您出了什么问题:您缺少程序集引用。 How to: Add or Remove References in Visual Studio
-
因为这只是您的第一个程序,最好重新启动并创建 Windows 窗体应用程序。 VS2010 项目向导将处理许多有关使用 windows 窗体的数据
-
dtb 评论的第一部分有点多余。显然,提问者缺少程序集引用。问题是如何解决这个问题,因为错误消息没有说明这一点。
标签: c# winforms visual-studio