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的位置。

  • 相关阅读:
    C# String.Compare 方法测试
    C#checked 与 unchecked
    C#枚举类型
    C#结构体
    C越界和溢出的区别
    python/matlab : 将txt文件中的数据读为numpy数组
    matlab程序里调用python文件
    Python
    Pycharm调试及快捷键技巧
    Pycharm远程连接服务器debug时报错
  • 原文地址:https://www.cnblogs.com/shawnzxx/p/3159066.html
Copyright © 2011-2022 走看看