更简洁的代码示例

win*_*yip 0 c#

有没有更简洁的写作方式?

articleCount += 1;
if (articleCount > 4)
{
    // Reset counter to 1
    articleCount = 1;
}
Run Code Online (Sandbox Code Playgroud)

Roy*_*tus 6

是:

if (++articleCount > 4) articleCount = 1;
Run Code Online (Sandbox Code Playgroud)


Glo*_*del 6

对于那些喜欢数学难题不可读代码的人,以下内容也可以:

articleCount = (articleCount % 4) + 1;
Run Code Online (Sandbox Code Playgroud)