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

  • 相关阅读:
    Android测试工具 UIAutomator入门与介绍
    C#异步编程
    懒得找,存个笔记:easyui combogrid 下拉+关键字搜索
    mssql replace
    序列化类型为XX的对象时检测到循环引用
    shell脚本运行python命令
    python技巧
    边缘检测测评标准
    mybatis 手动生成可执行sql
    Linux如何扩容物理文件系统分区
  • 原文地址:https://www.cnblogs.com/shawnzxx/p/3159066.html
Copyright © 2011-2022 走看看