2017-09-19 65 views
-3

我是新来的,通过视觉工作室使用C#C#,并通过企业下载。我试着从hello world项目开始。但是,程序不会编译,因为由于某种原因它不会识别“系统”标识符。 这里是我的代码(这是我从一个教程直抄)...C#标识符“系统”未定义

using System; 
using System.Collections.Generic; 
using System.Text; 

namespace ConsoleApplication1 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      Console.WriteLine("Hello, world!"); 
      Console.ReadLine(); 
     } 
    } 
} 

我使用不同的#includes和去除usings和似乎没有任何工作尝试。有任何想法吗? 在此先感谢!

+1

您的代码对我来说看起来不错.... – Isma

+1

您在此项目的解决方案资源管理器树的“参考”部分中看到了什么? –

+0

您是否创建了一个C++项目? – Tuco

回答

0

您使用的是C++项目模板,

  • 关闭Visual Studio的
  • 打开Visual Studio
  • 单击新建项目
  • 选择Visual C#中
  • 选择控制台应用程序
  • 键入项目名称,或保留默认一个
  • 社区法网k确定
+0

工作!非常感谢,请原谅我愚蠢的错误:P – Natalie

0

您需要确保您在解决方案资源管理器窗口中的解决方案下的参考列表中看到系统。

  1. 如果你没有在那里看到它,那么你需要使用NuGet包管理器(在Visual Studio工具菜单下找到)添加它。
  2. 如果做参考的在解决方案资源管理器窗口您的解决方案下的列表中找到系统尝试创建一个新的项目或清洗后重建解决方案(在Visual Studio中生成菜单下找到)。

这两个在过去为我工作。祝你好运我希望这可以帮助 我将她的代码复制到C#控制台应用程序项目中,并运行它,它工作得很好。她使用C#代码模板

她的代码:从https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/inside-a-program/hello-world-your-first-program

using System; 
namespace HelloWorld 
{ 
    class Hello 
    { 
     static void Main() 
     { 
      Console.WriteLine("Hello World!"); 

      // Keep the console window open in debug mode. 
      Console.WriteLine("Press any key to exit."); 
      Console.ReadKey(); 
     } 
    } 
} 

唯一的主要区别采取

using System; 
using System.Collections.Generic; 
using System.Text; 

namespace ConsoleApplication1 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      Console.WriteLine("Hello, world!"); 
      Console.ReadLine(); 
     } 
    } 
} 

代码是在main(),这是缺乏的String [] args来没有必要,因为它是可选的

下面是使用Visual Studio和C#控制台应用程序项目的运行,从她的代码完全复制的程序: Picture of Program code and output