C# 注释是编译器不执行的语句。C# 编程中的注释可用于提供代码、变量、方法或类的解释。借助注释,您还可以隐藏程序代码。
C# 中有两种类型的注释。
单行注释
多行注释
单行注释以 //(双斜杠)开头。让我们看一个 C# 中的单行注释示例。
using System;
public class CommentExample
{
public static void Main(string[] args)
{
int x = 10;//这里,x是一个变量
Console.WriteLine(x);
}
}输出:
10
C#多行注释用于注释多行代码。它被斜线和星号 (/* ..... */) 包围。让我们看一个 C# 中的多行注释示例。
using System;
public class CommentExample
{
public static void Main(string[] args)
{
/* 让我们声明和
C#中的打印变量。*/
int x=20;
Console.WriteLine(x);
}
}
输出:
20