Reputation: 469
In some languages, like Scheme, there's a way to comment out the rest of a file. Is there a way of doing this in C# without putting */ at the end of the file and /* where the comment begins? I'm just curious.
Upvotes: 0
Views: 58
Reputation: 6604
No, there is no method of commenting-to-end in C#. You only have //
and /* ... */
available to you. Here is an example of why you would not ever want a comment-to-end style in C#...
Consider the following:
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()
{
}
*/
}
}
The above shows how rest-of-line and block style comments work. Consider if you had a way to comment out the rest of a file, let's use ***
to indicate that the rest of the document should be commented out as an example.
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()
{
}
}
}
In the situation above, what you would end up doing is effectively this:
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.
*/
Without some way to tell the compiler to stop skipping lines, your code blocks will be unclosed and your code will not compile.
Upvotes: 1