Commenting 'else' statements

Jun 3, 2010 at 11:53 AM

Hi,

How can I best comment 'else' clauses.  Stylecop is happy with comments on 'if', but less so on the 'else'.  For example:

// Do we have an even number?
if (value % 2 == 0)
{
   returnValue = 1;
}
// Else is our value out of range
else if (value > 100)
{
    returnValue = 2;
}

This produces SA1515 and SA1108 on the second comment line (adding a blank line before the second comment line removes 1515, but 1108 remains).  Is there a way to comment the 'else' clause without having to move the comment inside the block (that is just above the returnValue=2)

Jun 3, 2010 at 1:03 PM
Edited Jun 3, 2010 at 1:05 PM

I do it like this:

 if (value % 2 == 0)
{
  // We have an even number

 returnValue = 1;
}
else if (value > 100)
{
// Value out of range
!
returnValue = 2;
}