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

时间:2014-07-30 07:45:54

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

这个警告有什么意义?

1 个答案:

答案 0 :(得分: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.");
    }

查看herethere