VB .NET 中缺少块注释?

发布于 2024-08-20 08:24:37 字数 62 浏览 8 评论 0原文

只是一个感兴趣的问题:有谁知道为什么 VB .NET 中没有块注释功能? (除非真的有——但我还没有遇到过。)

Just a question of interest: Does anyone know why there's no block comment capability in VB .NET? (Unless there really is - but I've never yet come across it.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

谁许谁一生繁华 2024-08-27 08:24:37

它是 Visual Basic 语法的副作用,换行符终止语句。这使得多行注释与编译器解析语言的基本方式非常不兼容。在大括号语言中这不是问题,换行符只是空格。

这从来都不是一个真正的问题,Visual Basic 长期以来一直拥有强大的 IDE 支持。注释掉多行是一个 IDE 功能,编辑 + 高级 + 注释选择。

It is a side-effect of the Visual Basic syntax, a new-line terminates a statement. That makes a multi-line comment pretty incompatible with the basic way the compiler parses the language. Not an issue in the curly brace languages, new-lines are just white space.

It has never been a real problem, Visual Basic has had strong IDE support for a very long time. Commenting out multiple lines is an IDE feature, Edit + Advanced + Comment Selection.

眼藏柔 2024-08-27 08:24:37

在这里完全滥用编译器指令...但是:

#If False Then
Comments
go
here
#End If

您没有获得正确代码着色的好处(使用默认颜色方案时它不会显示为绿色)并且隐式行继续系统会自动缩进段落中的行在第二行。但编译器会忽略该文本。

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.

2024-08-27 08:24:37

正如“代码中的注释”中所示,没有任何其他方式:

如果您的注释需要多行,请在每一行上使用注释符号,如下例所示。

' 该注释太长,无法放在一行中,因此我们中断 
' 分成两行。有些注释可能需要三行或更多行。

同样,REM 声明的帮助指出:

注意:
您不能使用续行序列 (_) 来继续 REM 语句。一旦注释开始,编译器就不会检查字符的特殊含义。对于多行注释,请在每行上使用另一个 REM 语句或注释符号 (')。

As can be read in “Comments in Code“ there isn't any other way:

If your comment requires more than one line, use the comment symbol on each line, as the following example illustrates.

' This comment is too long to fit on a single line, so we break 
' it into two lines. Some comments might need three or more lines.

Similarly, the help on the REM statement states:

Note:
You cannot continue a REM statement by using a line-continuation sequence (_). Once a comment begins, the compiler does not examine the characters for special meaning. For a multiple-line comment, use another REM statement or a comment symbol (') on each line.

凉墨 2024-08-27 08:24:37

根据要忽略的行数,可以使用编译器指令来代替。从技术上讲,它可能并不等同于注释(例如,您无法获得注释的语法着色),但它无需单独注释多行即可完成工作。所以你只需再添加 3 行代码即可。

#Const COMMENT = "C"
'basically a false statement
#If COMMENT = "Y"  Then
   'code to be commented goes between #If and #End If
   MsgBox('Commenting failed!')
#End If

这是假设目的是忽略代码块而不是添加文档(“注释”实际上是用来做什么的,但我也不介意为此使用编译器指令)。

然而,当需要注释的行数大约为 10 行时,所需的工作量使得此方法变得不方便。

参考:http://msdn.microsoft.com/en-us/library/tx6yas69 .aspx

Depending on how many lines are to be ignored, one can use compiler directives instead. It may not be technically equivalent to comments (you don't get the syntax coloring of comments, for example), but it gets the job done without commenting many lines individually. So you just add 3 more lines of code.

#Const COMMENT = "C"
'basically a false statement
#If COMMENT = "Y"  Then
   'code to be commented goes between #If and #End If
   MsgBox('Commenting failed!')
#End If

This is assuming the purpose is for ignoring blocks of code instead of adding documentation (what "comments" are actually used for, but I also wouldn't mind using compiler directives for that).

The effort required however, makes this method inconvenient when there are just around 10 lines to comment.

Reference: http://msdn.microsoft.com/en-us/library/tx6yas69.aspx

忆悲凉 2024-08-27 08:24:37

由于 VB.Net 支持 XML,因此您可以在代码中编写以下内容:

Dim ignored =
    <!-- 
             here my multiline 
             block comment 
    -->

它甚至会使行的注释颜色为绿色。

Since VB.Net supports XML, you could write the following in your code:

Dim ignored =
    <!-- 
             here my multiline 
             block comment 
    -->

It will even make the lines in comment-green color.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文