[C#基础2/21] C#注释与文件结构
1. 注释
C# 支持两种不同形式的注释。 单行注释以 //
开头,并在该代码行末尾结束。 多行注释以 /*
开头,以 */
结尾。 下面的代码示例演示了每种注释:
// This is a single line comment. /* This could be a summary of all the code that's in this class. You might add multiple paragraphs, or links to pages like https://learn.microsoft.com/dotnet/csharp. You could even include emojis. This example is 🔥 Then, when you're done, close with */
某些注释以三个斜杠开头:///
。 三斜杠注释是 XML 文档注释。 编译器读取这些注释以生成人工文档。
- 文档注释
/// <summary> /// 文档注释 /// </summary>
4.1 文件结构
摘自刘铁猛的B站视频
示例
using System; // 引用命名空间 namespace demo // 命名空间 { internal class Program // 类型 { static void Main(string[] args) // 函数/方法,此处为主函数 { Console.WriteLine("Hello"); Console.ReadLine(); // 类似于python的input函数,用于暂停程序 } } }