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

  • 相关阅读:
    编写登陆认证程序
    Ubuntu18.04安装MySQL
    python输出的高亮显示
    河北省赛
    dp
    迷宫问题
    牛客-幸运数字Ⅱ
    [管理运筹学]线性规划&单纯形法的各种姿势(题目:[NOI2008]志愿者招募)
    [管理运筹学]指派问题的匈牙利算法及其c++实现 (例:「网络流 24 题」分配问题 )
    打算在CSDN写了,虽然博客园也很好
  • 原文地址:https://www.cnblogs.com/shawnzxx/p/3159066.html
Copyright © 2011-2022 走看看