C# 入门
C# IDE
开始学习 C# 的最简单方法是使用一个 IDE。
IDE(集成开发环境)用于编辑和编译代码。
在我们的教程中,我们将使用 Visual Studio Community,可以从此链接免费下载:
https://visualstudio.microsoft.com/vs/community/
用 C# 编写的应用程序使用 .NET Framework,因此使用 Visual Studio 是有意义的,因为该程序、框架和语言都是由 Microsoft 创建的。
C# 安装
下载并安装 Visual Studio 安装程序后,选择 .NET 工作负载并单击修改/安装按钮:

安装完成后,单击启动按钮以开始使用 Visual Studio。
在启动窗口中,选择创建新项目:

然后单击安装更多工具和功能链接:

从列表中选择控制台应用程序 (.NET Core),然后单击“下一步”按钮:

为您的项目输入一个名称,然后单击创建按钮:

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

代码应如下所示:
Program.cs
using System; namespace HelloWorld { class Program { static void Main(string[] args) { Console.WriteLine("Hello World!"); } } }
如果您不理解上面的代码,请不要担心 - 我们将在后面的章节中详细讨论。现在,请专注于如何运行代码。
通过按键盘上的 F5 按钮(或单击调试 -> 开始调试)来运行程序。这将编译并执行您的代码。结果将如下所示:
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# 程序。
在 W3School 学习 C#
在 W3School.com.cn 学习 C# 时,您可以使用我们的“亲自试一试”工具,该工具同时显示代码和结果。这将使您在前进时更容易理解每个部分:
Program.cs
using System; namespace HelloWorld { class Program { static void Main(string[] args) { Console.WriteLine("Hello World!"); } } }
结果:
Hello World!