C#——编程风格

来源:互联网 发布:淘宝客服ipad 编辑:程序博客网 时间:2024/06/07 22:07

较正规的编程风格

  1. 在一个二元操作符的每一边都加一个空格
  2. 在每一个逗号后面加一个空格
  3. 每一个关键字后面加一个空格
  4. 一行一个语句
  5. 分号前不要有空格
  6. 函数的圆括号和参数之间不加空格
  7. 在一元操作符和操作数之间不加空格
  • 在一个二元操作符的每一边都加一个空格
    Console.WriteLine("{0}", result / 2);   //推荐
    Console.WriteLine("{0}", result/2);    //不推荐
  • 在每一个逗号后面加一个空格
    Console.WriteLine("{0}", result / 2);   //推荐
    Console.WriteLine("{0}",result / 2);   //不推荐
  • 每一个关键字后面加一个空格
    If (OneLine(comment))……  //推荐
    If(OneLine(comment))……  //不推荐
  • 分号前不要有空格
    Console.WriteLine("{0}", result / 2);  //推荐
    Console.WriteLine("{0}", result / 2) ;  //不推荐
  • 函数的圆括号和参数之间不加空格
    if (OneLine(comment))……//推荐
    if (OneLine ( comment ))……//不推荐
  • 在一元操作符和操作数之间不加空格
    ++keywordCount;  //推荐
    ++ keywordCount;  //不推荐

0 0
原创粉丝点击