C#编程风格 - 线长/包装线 [英] C# coding style - line length / wrapping lines

查看:108
本文介绍了C#编程风格 - 线长/包装线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否换行的帮助代码的可读性?

Does line wrapping help with code readability?

有没有使用行延续?

为什么要用这样的:

SomeMethod(int someInt, Object someObject,
   String someString, bool someBool)
{
    ...
}

而不是这样的:

SomeMethod(int someInt, Object someObject, String someString, bool someBool)
{
    ...
}

编辑:重新措辞我的问题,从行延续到换行

re-worded my question from line continuation to line wrapping

推荐答案

线延续不在C#中使用,因为一个明确的行结束符(; )是必需的。

Line continuations are not used in C#, since an explicit line terminator (;) is required.

如果你问,英寸就风格而言,它是否是一个好主意,打破了行成多行,这是值得商榷的。该规则的StyleCop的强制既可以在一行定义一条线,或每个元素是在单独的行。我个人认为这是一个很好的指引,我通常会选择彻底打破一行到它的部分,如果它太长,不适合成为一个很好的80-90个字符宽主编。

If you're asking, in terms of style, whether it's a good idea to break a line into multiple lines, that's debatable. The StyleCop rules force a line to either be defined on a single line, or for every element to be on a separate line. I personally think this is a good guideline, and I usually choose to break a line completely into its parts if it's too long to fit into a good 80-90 character wide editor.

编辑回应新的问题:

在这种情况下,我会按照上述准则。就个人而言,在特定的情况下,我会离开这个在一行:

In this case, I would follow the guidelines above. Personally, in your specific case, I'd leave this on one line:

SomeMethod(int someInt, Object someObject, String someString, bool someBool) 
{ 
    ... 
} 

这是一个不错的,总之moethod声明,我认为没有理由分裂它。我只是想,如果参数的数量分割它,并且类型的长度,成为迄今为止长一行文字。

This is a nice, short moethod declaration, and I see no reason to split it. I'd only split it if the number of arguments, and the lengths of the types, became far to long for one line of text.

如果你把它分解,不过,我想它分割成单独的行每​​个参数:

If you do split it, however, I'd split it into separate lines for each argument:

SomeMethod(
    int someInt, 
    Object someObject, 
    String someString, 
    bool someBool) 
{ 
    ... 
} 

这个方式,至少很明显如何以及为什么它的分裂和开发人员不小心就会跳过一个说法,因为两者是在同一行。

This way, at least it's obvious how and why it's split, and a developer won't accidentally skip one argument since two are on a single line.

这篇关于C#编程风格 - 线长/包装线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆