2015-11-05 156 views
0

在某些语言中,如Scheme,有一种方法可以将文件的其余部分注释掉。有没有在C#中执行此操作的方法,而不将* /放在文件末尾和/ *开始的地方?我只是好奇。评论C#文件的其余部分#

+3

您只能使用块注释('/ * blah * /')或其他行注释('// blah') – DavidG

+0

不是我所知道的。虽然如果你想用Visual Studio快捷方式快速完成它,你可以按'CTRL + SHIFT + END'(突出显示当前插入位置之后的所有内容),然后按'CTRL + K,CTRL + C'(注释掉它)。 –

+1

问题在于你最终会注释掉任何块关闭('}'),这也是为什么“注释结束”样式不可行。 – gmiley

回答

1

不,没有在C#中进行注释的方法。您只有///* ... */可供您使用。这就是为什么你没有想在C#中评论到终端的风格的例子...

考虑以下几点:

namespace TestNamespace 
{ 
    public class TestClass 
    { 
     public void DoSomething() 
     { 
     // Here is a comment-to-end-of-line. 

     } 
     /* The entire DoSomethinElse member is commented out... 
     public void DoSomethingElse() 
     { 

     } 
     */ 
    } 
} 

上面显示了如何其余的行和块样式评论工作。考虑如果您有办法评论文件的其余部分,那么让我们使用***来指示文档的其余部分应作为示例注释掉。

namespace TestNamespace 
{ 
    public class TestClass 
    { 
     public void DoSomething() 
     { 
     // Here is a comment-to-end-of-line. 

     } 
     *** The rest of the document should be commented out from here... 
     public void DoSomethingElse() 
     { 

     } 

    } 
} 

在上面的情况,你会最终做实际上是这样的:

namespace TestNamespace 
{ 
    public class TestClass 
    { 
     public void DoSomething() 
     { 
     // Here is a comment-to-end-of-line. 

     } 
     /* The rest of the document should be commented out from here... 
     public void DoSomethingElse() 
     { 

     } 
    } 
} 
     That includes all of the remaining block closings, which will cause compile errors. 
     */ 

如果没有某种方式告诉编译器停止跳跃的线条,你的代码块将是未封闭的,你的代码不会编译。

相关问题