// C# 实例:简单的控制台应用程序
using System;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
// 输出 "Hello, World!" 到控制台
Console.WriteLine("Hello, World!");
// 等待用户输入后退出
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
}
}
namespace HelloWorld
定义了一个命名空间,class Program
定义了一个类。命名空间用于组织代码,类是面向对象编程的基本构造块。static void Main(string[] args)
是程序的入口点。每个 C# 控制台应用程序都必须有一个 Main
方法。"Hello, World!"
。希望这个示例能帮助你理解 C# 的基本结构和语法。
下一篇:c#正则表达式提取文本
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站