4

好像没有问过这个问题。如果重复,请发表评论。

据说我#region在 C# 代码中有注释。

#region if this comment is very long, can I divide the comment into multi-lines?

   // my code is here

#endregion

是否可以#region像底部代码一样将注释分成多行?

#region the comment is separated into
#region-2 two lines.

   // my code is here

#endregion
4

3 回答 3

7

我不认为长注释是该#region指令的预期用途。当我想到“区域”时,我会想到诸如“私有成员”或“服务声明”或“重载构造函数”或类似性质的简单标签之类的东西。

如果您有很长的评论,我会将其包含在该区域的顶部,如下所示:

#region Some Region Name

    /**
     * Here is a decently lengthy comment which describes the
     * group of class members within the region.
     */

    /// <summary>
    /// A regular member's comment documentation.
    /// </summary>
    public int MyRegionProperty { get; set; }

    // etc...

#endregion

MSDN将后面的部分描述#region为“名称”,而不是评论。名称应该足以描述该地区的内容,仅此而已。

于 2012-11-16T04:21:44.473 回答
2

#Region来自MSDN的定义

`#region 允许您指定在使用 Visual Studio 代码编辑器的大纲功能时可以展开或折叠的代码块。在较长的代码文件中,能够折叠或隐藏一个或多个区域很方便,这样您就可以专注于您当前正在处理的文件部分。

它的主要目的是允许概述您的代码并能够折叠区域(区域)以提高可读性。如果您想要扩展评论,您将不得不使用标准 C# 评论

于 2012-11-16T04:25:28.190 回答
1

Region 用于对可以展开和折叠的代码块进行分组,不用于评论:

在此处输入图像描述

浏览此http://www.dotnetperls.com/region

于 2012-11-16T04:29:47.663 回答