VB .NET 中缺少块注释?
只是一个感兴趣的问题:有谁知道为什么 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
它是 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.
在这里完全滥用编译器指令...但是:
您没有获得正确代码着色的好处(使用默认颜色方案时它不会显示为绿色)并且隐式行继续系统会自动缩进段落中的行在第二行。但编译器会忽略该文本。
Totally abusing compiler directives here... but:
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.
正如“代码中的注释”中所示,没有任何其他方式:
同样,REM 声明的帮助指出:
As can be read in “Comments in Code“ there isn't any other way:
Similarly, the help on the REM statement states:
根据要忽略的行数,可以使用编译器指令来代替。从技术上讲,它可能并不等同于注释(例如,您无法获得注释的语法着色),但它无需单独注释多行即可完成工作。所以你只需再添加 3 行代码即可。
这是假设目的是忽略代码块而不是添加文档(“注释”实际上是用来做什么的,但我也不介意为此使用编译器指令)。
然而,当需要注释的行数大约为 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.
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
由于 VB.Net 支持 XML,因此您可以在代码中编写以下内容:
它甚至会使行的注释颜色为绿色。
Since VB.Net supports XML, you could write the following in your code:
It will even make the lines in comment-green color.