注释不能放在括号内的语句中

本文关键字:语句 不能 注释 | 更新日期: 2023-09-27 18:15:28

我在c#文件中使用了StyleCop,它给出了警告:

SA1108: CSharp。可读性:注释不能放在括号内的

语句中

:

// 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.");
}

这个警告的意义是什么?

注释不能放在括号内的语句中

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.");
    }

到处看看