评论可能不会放在括号内的陈述中

Cod*_*man 4 c# coding-style stylecop

我在我的C#文件上使用StyleCop并发出警告:

SA1108:CSharp.Readability:注释不能放在括号内的语句中

对于以下代码块:

// 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.");
}
Run Code Online (Sandbox Code Playgroud)

这个警告有什么意义?

Mat*_* R. 5

StyleCop告诉你,你应该在括号内的else语句上面替换/重新组织你的注释,比如

    // 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.");
    }
Run Code Online (Sandbox Code Playgroud)

看看这里那里.