Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A comment may not be placed within the bracketed statement

I am using StyleCop on my C# files and it gives the warning :

SA1108 : CSharp.Readability : A comment may not be placed within the bracketed statement

for the following block of code :

// checking if the person is born or not.
if (AgeUtilities.IsPersonBorn(person.BirthDate) == false)
{
    Console.WriteLine("Error....The user is not yet born.");
}

// checking if the person's age is possible or not.
else if (AgeUtilities.IsPersonLongAgePossible(age, EXPECTEDAGELIMIT) == false)
{
    Console.WriteLine("This age is not possible in Today's world.");
}

What is the significance of this warning?

like image 306
Coding man Avatar asked Jul 30 '14 07:07

Coding man


1 Answers

StyleCop tells you that you should replace/reorganise your comment above the else-statement inside the brackets, like

    // checking if the person is born or not
    // if not: check if the person's age is possible or not
    if (AgeUtilities.IsPersonBorn(person.BirthDate) == false)
    {
        Console.WriteLine("Error....The user is not yet born.");
    }
    else if (AgeUtilities.IsPersonLongAgePossible(age, EXPECTEDAGELIMIT) == false)
    {
        Console.WriteLine("This age is not possible in Today's world.");
    }

Have a look here and there.

like image 68
Matthias R. Avatar answered Nov 18 '22 20:11

Matthias R.