2015-11-05 39 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. 
     */ 

如果沒有某種方式告訴編譯器停止跳躍的線條,你的代碼塊將是未封閉的,你的代碼不會編譯。