Style 全般
インデント
インデントには半角スペース4つを使う。
namespace Microsoft.Office
{
public class PowerPoint
{
public void DoSomething()
{
return;
}
}
}
namespace Microsoft.Office
{
public class PowerPoint
{
public void DoSomething()
{
return;
}
}
}
スペースの挿入
単項演算子の前後にはスペースを入れない
i++;
++i;
i ++;
++ i;
二項演算子と三項演算子の前後にはスペースを入れる
y = m * x + b;
c = a | b;
abs = 0 <= n ? n : -n;
y=m*x+b;
c = a|b;
abs = 0 <= n?n:-n;
namespace、クラス、構造体メンバーにアクセスするための .
の前後にはスペースを入れない。
using System.IO;
c.re;
using System . IO;
c . re;
,
, ;
の前にはスペースを入れない。,
の後ろにはスペースを入れる。
y = m * x + b;
f(a, b);
y = m * x + b ;
f(a , b);
f(a,b);
キーワード (予約語、識別子、リテラル) の前後にはスペースを入れる。
if (condition)
if(condition)
ただし関数名と引数を囲む (
の間にはスペースを入れない。
DoSomething();
DoSomething ();
改行
1つの行に複数の式を書かない。
x++;
y++;
if (condition)
doSomething();
x++; y++;
if (condition) doSomething();
ブロックを囲む {
, }
には、それぞれ1行使う。
class
, struct
, enum
, interface
, if
, for
, foreach
, while
, switch
全て。
public void DoSomething(int[] numbers)
{
foreach (var number in numbers)
{
Console.WriteLine(number.ToString());
}
}
public void DoSomething(int[] numbers) {
foreach (var number in numbers) {
Console.WriteLine(number.ToString());
}
}