[Unity] Unity C# Basics (14) Notes


note

line comment

// 注释内容

section comment

/* 注释内容 */

XML comments

/// <summary>
/// 注释内容
/// </summary>

/// It is a smart comment, also known as an xml comment, which will be compiled and generate an xml file in the executable file. Affects compilation speed, but not code execution speed.

Level 1 Annotation

  1. Describe the type, the function is similar to <summary>, it is said that it is recommended to use <remarks>;
  2. Annotate classes, methods, properties, or fields of common types;
  3. It is mainly used for attribute annotations, indicating the meaning of attributes, and can be used with <summary>;
  4. Used to describe the parameters of the method, format: value;
  5. It is used to define the return value of the method. For a method, after entering ///, <summary>, list and <returns> will be added automatically;
  6. Define the exceptions that may be thrown, format:;
  7. Used to give how to use a method, property or field;
  8. Access permissions for methods involved;
  9. It is used to refer to something else :), you can also set properties through cref;
  10. XML comments used to indicate external;

secondary comment

  1. or 主要用于加入代码段;
  2. The function is similar to the < p > tag in HTML, which is segmented;
  3. Used to refer to a parameter;
  4. The role is similar to <seealso>, which can indicate other methods;
  5. is used to generate a list;

In addition, you can customize the XML tags.

comment line break

When C# smart comments, it is often hoped that it can be displayed as a newline during development, making the prompt more friendly! I have always wanted to realize it, but today I stumbled upon how simple it is, just use tags such as , or inside tags.

Ways to Wrap Comments at Development Time
Tags are used inside tags such as , , or to allow you to add structure to your text.

/// <summary> 
/// 基类(第 1 行) 
///<para> 说明:(第 2 行)</para> 
///<para>  封装一些常用的成员(第 3 行)</para> 
///<para>  前面要用全角空格才能显示出空格来(第 4 行)</para> 
/// </summary> 
public class MyBase 
{
    
     
      /// <summary> 
      /// 构造函数(第 1 行) 
      ///<para> 说明:(第 2 行)</para> 
      ///<para>  初始化一些数据(第 3 行)</para> 
      /// </summary> 
      public MyBase() 
      {
    
     
            // 
            //TODO: 在此处添加构造函数逻辑 
            // 
       } 
} 

TODO comments

After the TODO comment is used, it can help record the unfinished tasks in the project.
Use TODO comments in the code segment, such as
"//TODO: This has not been tested yet"

In View -> Task List, select Comments to view the positions of all marked TODOs in the project.

example:

/// <summary>
/// 防御塔目标
/// <para>通过LockTarget锁定目标。</para> 
/// </summary>
protected Transform _target;// TODO 暂时为单个目标,后续需要改成列表。

insert image description here


Most of the content of this article is transferred from the original article of CSDN blogger "Leo Chaw", the original link: https://blog.csdn.net/liankui6027/article/details/111831885

For more information, please check the general catalog [Unity] Unity study notes catalog arrangement

Guess you like

Origin blog.csdn.net/xiaoyaoACi/article/details/127807056