C#中的注释符

转载https://www.cnblogs.com/HelloZyjS/p/5993380.html

1.软件行业的道德规范

(1).程序员在日常写代码的过程中,一定要养成注释的好习惯,方便后面对理解和使用.

(2).在给标识符命名的时候一定要规范,有理有据的,名字不能瞎写.

2.注释

注释符的作用:

(1).注释需要解释的代码

(2).注销掉代码,就是将不想参与执行的代码注销

C#语言中包含了三种注释符

(1).单行注释   //

(2).多行注释  /*要注释的内容*/       注意:多行注释不能嵌套使用

(3).文档注释 ///     文档注释可以用来注释方法,也可以用来注释类.

单行注释符   //

 
  1. class Program
  2. {
  3. static void Main(string[] args)
  4. {
  5. //这一行代码的作用是将hello world打印到控制台中
  6. Console.WriteLine("Hello world");
  7.  
  8. // Console.WriteLine("不想输出的代码"); 此行代码被注销了
  9. //这行代码的作用是将程序暂停在这个地方.
  10. Console.ReadKey();
  11. }
  12. }

多行注释  /**/

 
  1. class Program
  2. {
  3. static void Main(string[] args)
  4. {
  5. /*以下是不想要的代码
  6. Console.WriteLine("Hello world");
  7. Console.WriteLine("Hello world");
  8. Console.WriteLine("Hello world");
  9. Console.WriteLine("Hello world");
  10. Console.WriteLine("Hello world");
  11. Console.WriteLine("Hello world");
  12. Console.WriteLine("Hello world");
  13. Console.WriteLine("Hello world");
  14. */
  15.  
  16. Console.ReadKey();
  17. }
  18. }

文档注释  ///

 
  1. class Program
  2. {
  3. static void Main(string[] args)
  4. {
  5. Console.WriteLine("Hello world");
  6. Console.ReadKey();
  7. }
  8.  
  9. /// <summary>
  10. /// 这个方法的作用就是求两个整数之间的最大值
  11. /// </summary>
  12. /// <param name="n1">第一个整数</param>
  13. /// <param name="n2">第二个整数</param>
  14. /// <returns>返回比较大的那个数字</returns>
  15. public static int GetMax(int n1, int n2)
  16. {
  17. return n1 > n2 ? n1 : n2;
  18. }
  19. }
  20.  
  21. /// <summary>
  22. /// 这个类用来描述一个人的信息 从姓名 性别 年龄 描述
  23. /// </summary>
  24. public class Person
  25. {
  26. public string Name
  27. {
  28. get;
  29. set;
  30. }
  31.  
  32. public int Age
  33. {
  34. get;
  35. set;
  36. }
  37.  
  38. public char Gender
  39. {
  40. get;
  41. set;
  42. }
  43. }

猜你喜欢

转载自blog.csdn.net/chqj_163/article/details/88425141