块注释 VB/VB.NET 代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1068395/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Block commenting VB/VB.NET code
提问by
How to comment multiple lines of code/block of code in VB?
如何在 VB 中注释多行代码/代码块?
回答by Mehrdad Afshari
VB doesn't have such a construct at the language level. It has single line comments using apostrophe character:
VB 在语言级别没有这样的结构。它有使用撇号字符的单行注释:
' hello world
' this is a comment
Rem this is also a comment
However, Visual Studio has a functionality to automate this task. Select the lines you want and press Ctrl+K+Cfor commenting and Ctrl+K+Ufor uncommenting (General Development Settings shortcuts, look at the "Edit ->
Advanced" menu while selecting some code to see the shortcuts).
但是,Visual Studio 具有自动执行此任务的功能。选择您想要的线,然后按Ctrl+ K+C的注释和Ctrl+ K+U的反注释(常规开发设置快捷键,看看“编辑->
高级”菜单,同时选择一些代码来看看快捷方式)。
回答by user665301
Totally abusing compiler directives here... but:
在这里完全滥用编译器指令......但是:
#If False Then
Comments
go
here
#End If
You don't get the benefits of proper code coloration (it doesn't show in green when using the default color scheme) and the implicit line-continuation system automatically indents lines in a paragraph starting at the second line. But the compiler will ignore the text.
您无法获得正确代码着色的好处(使用默认配色方案时它不会显示为绿色),并且隐式续行系统会自动缩进段落中从第二行开始的行。但是编译器会忽略文本。
回答by MarkJ
The other answersexplain how to comment/uncomment automatically in VB.NET. Just for completeness, in VB6 use these toolbar buttons: . More details here.
在其他的答案解释如何注释/取消注释在VB.NET自动。为了完整起见,在 VB6 中使用这些工具栏按钮:. 更多细节在这里。
回答by Magnus
Here is a cludgy way to make a multiline comment which is also collapsible.
这是一种制作多行注释的笨拙方法,该注释也是可折叠的。
If <![CDATA[ Multiline comment about this and that
Comment about this
and that and so on
with lots of lines
]]> Is Nothing Then : End If
It looks like this when you collapse it
当你折叠它时它看起来像这样
If <![CDATA[ Multiline comment about this and that ... Is Nothing Then : End If
回答by Laxmi
Ways you can comment code in VB:
在 VB 中注释代码的方法:
- by using CTRL+K+C
- adding '(Apostrophes symbol) in front of your code which you want to make it as comment
- adding
rem
in front of your code which you want to make it as comment. (Note:rem
means remarks -->rem
is used to include explanatory remarks in the source code of a program.) - just select the particular code and click on the option called "comment out the selected lines"in the toolbar.
#if false
(enter your code here)#endif
-- the code inside these 2 statements will be commented.
- 通过使用CTRL+ K+C
- 在您想要将其作为注释的代码前添加 '(撇号符号)
rem
在您想要将其作为注释的代码前面添加。 (注:rem
表示注释 -->rem
用于在程序的源代码中包含解释性注释。)- 只需选择特定的代码,然后单击 工具栏中名为“注释掉所选行”的选项。
#if false
(在此处输入您的代码)#endif
——这两个语句中的代码将被注释。
回答by BGD
Select the lines you need to comment and press keys CTRL+K+C.
选择您需要注释的行,然后按CTRL+ K+键C。
If you need to uncomment use CTRL+K+U
如果您需要取消注释使用CTRL+ K+U
回答by Ananth
Select the lines that you want to comment.
选择要注释的行。
Press CTRL+K+Cin Visual Studio. It will help you to comment multiple lines at once.
按CTRL+ K+C在Visual Studio。它将帮助您一次注释多行。
回答by Jared
To comment out a big section of code you highlight the code you want to comment out, then you hit ctrl+K, then hit ctrl+C. To un-comment a block of commented code you hit ctrl+K, then hit ctrl+U.
要注释掉一大段代码,请突出显示要注释掉的代码,然后点击ctrl+ K,然后点击ctrl+ C。要取消注释一块已注释的代码,请点击ctrl+ K,然后点击ctrl+ U。
回答by Andreas
in VS2010 VB.NET, type 3 times ' above a class/function/property/declaration
在 VS2010 VB.NET 中,在类/函数/属性/声明上方键入 3 次 '
then it will auto generate a comment block :
然后它会自动生成一个评论块:
''' <summary>
''' GRP Business partner ID
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
same thing in C# but type 3 times /
在 C# 中同样的事情,但键入 3 次 /
/// <summary>
///
/// </summary>