zoukankan      html  css  js  c++  java
  • Unity中的C#规则

    命名

    文件名和Class要一致(CamelCase)

    类公共和保护类型Property(CamelCase)

    类的公共和保护类型Fields(CamelCase)* 先采用.Net的命名方法,如果出现问题以后改成小写。

    Methord和Function(CamelCase)

    私有字段或者Property(_camelCase)

    parameter(camelCase)

    定义变量的位置最好在使用前,离得越近越好

    Type Var

        var x = 0; //x is an int
        var x = 0f; //x is a float
        var x = new Dictionary<string, float>(); // x is a dictionary of string to float
    View Code
    这样有的时候会使代码更容易阅读
    var lookupWeight = new Dictionary<string, float>(); 
    Dictionary<string, float> lookupWeight = new Dictionary<string, float>();
    //第一个更好读
    View Code

    同时也不用关心返回的到底是什么类型

    var newEnemy = CreateEnemy("Bob", EnemyType.pedanticProgrammer);
    newEnemy.EvolveNow();  //Intellisense knew what newEnemy was
                              //I don't need to
    View Code

    This becomes even more important when using Linq or anonymous classes because it can actually be very hard to work out what the return value is, even though you (and again, intellisense) know exactly how to use it.

     SubClass and Enums

    SubClass可以定义在一个类外或者内,如果只是为了作为另外一个类或者类的方的reference那么定义在类内。 If you define subclasses then they should come at the bottom of your outer class definition.  Remember to use #regions to simplify your file structure.

     Enum的话如果经常在类外使用,最好定义在gloable的位置。

  • 相关阅读:
    poj 1037 三维dp
    poj 3311 floyd+dfs或状态压缩dp 两种方法
    HDU 5761 物理题
    HDU 5752
    Codeforces Round #328 (Div. 2) C 数学
    cakephp中sql查询大于
    cakephp获取最后一条sql语句
    iconv()错误
    sql时间戳转日期格式
    接口报错
  • 原文地址:https://www.cnblogs.com/shawnzxx/p/3159066.html
Copyright © 2011-2022 走看看