开发者

What is the difference between /// and #region in c#?

开发者 https://www.devze.com 2023-01-16 16:48 出处:网络
What is the difference between //开发者_高级运维/<Summary> and #region ...#endregion statements in c#? Which one the best?#region isn\'t a comment statement at all. It\'s for marking sections of

What is the difference between //开发者_高级运维/<Summary> and #region ...#endregion statements in c#? Which one the best?


#region isn't a comment statement at all. It's for marking sections of code. /// is for documentation comments.


/// <summary>
/// Three forward slashes denote a documentation comment, which can be used in
/// conjunction with documentation tooling to generate API documentation for
/// your code.
/// </summary>

// two forward slashes denote a code comment, which you can use to provide
// commentary within your code

/*
This style of comment is called a block comment, which can be used to easily
comment out large blocks of text within your code
*/

#region Some Region Name

// the above region allows the developer to collapse/uncollapse everything
// within it, as long as their IDE supports regions
public void SomeMethod()
{
}

#endregion


#region makes your code readable/maintainable/ more organized
/// documents code!


/// is for XML comments while region in not for commenting but for grouping code section together.


/// -> can be used for some comments

#region ...#endregion -> can be used to mark particular set of code to a region,easy to reffer

#region MainMethod

        /// <summary>
        /// Comments
        /// </summary>
        static void Main()
        {
            //Your code
        } 
        #endregion


Completely different things, one is for commenting/documentation, the other for hiding code.

XML Comments (///)

#Region


/// is used to insert XML Comments in your code. Xml comments allow you to build an output Xml file from you project: This file is later used by Visual Studio to show you intellisense tooltip with the comments you inserted. Moreover, you can use eit to build your own documentation. See here an article about how to build documentation from your source code Xml comments

#region is used to organize your code. It is only useful within IDE which understand it (VS), allowing you to collapse or expand every region of code you define with #region/#endregion


A region is used to collapse a large area of code and the // is used to add notes without the computer reading it.

#region your large code
loads of code in this area.
#endregion

//This is just a note that the computer won't read.
0

精彩评论

暂无评论...
验证码 换一张
取 消