C# 下载安装

C# IDE 下载

开始使用C#最简单的方法是使用IDE。

IDE(集成开发环境)用于编辑和编译代码。

在我们的教程中,将使用Visual Studio Community,https://visualstudio.microsoft.com/vs/community/下载。

用C#编写的应用程序使用.NET框架,因此使用Visual Studio是有意义的,因为程序、框架和语言都是由Microsoft创建的。


C# 安装

下载并安装Visual Studio安装程序后,选择.NET工作负载并单击Modify/Install按钮:

安装完成后,单击Launch按钮开始使用Visual Studio。

在开始窗口中,选择创建新项目Create a new project

然后单击安装更多工具和功能"Install more tools and features"按钮:

从列表中选择"Console App (.NET Core)",然后单击下一步按钮:

输入项目名称,然后单击创建按钮:

Visual Studio 将自动为您的项目生成一些代码:

代码应该如下所示:

Program.cs

using System;

namespace HelloWorld
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine("Hello World!");    
    }
  }
}

运行实例 »

如果您不理解上面的代码,请不要担心-我们将在后面的章节中详细讨论。现在,关注如何运行代码。

按键盘上的F5按钮运行程序(或单击调试"Debug"->开始调试Start Debugging)。这将编译并执行您的代码。其结果如下:

Hello World!
C:\Users\Username\source\repos\HelloWorld\HelloWorld\bin\Debug\netcoreapp3.0\HelloWorld.exe (process 13784) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .

祝贺! 现在您已经编写并执行了第一个 C# 程序。


在本站学习 C#

在本站学习C#,可以使用"运行实例"工具,它显示了代码和结果。这将使您更容易理解每一部分:

Program.cs

using System;

namespace HelloWorld
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine("Hello World!");    
    }
  }
}

结果:

Hello World!

运行实例 »