C#语言数组,字符串,static静态,const

数组:

                  int[]int_set;//数组对象引用

       //创建数组

       int_set = new int[10];//

       //访问数组

       int_set[0] = 1;

       int_set[1] = 2;

       int_set[2] = 3;//数组越界问题

       int index=5;

       int_set[index] = 10;

       //数组的访问

       for (int i = 0; i < 10;i++ )

       {

           Debug.Log(int_set[i]);

       }

String :字符串

                  //创建字符串

       string str=string.Format("{0},{1},{2}", "xiaoming",10, "male");

       Debug.Log(str);

       //判断字符串是否相等

       str = "limin";

       if(str.Equals("limin")){

           Debug.Log("相等");

       }

       //将所有字母转化为大写

       Debug.Log(str.ToUpper());

       //将所有字母转化为小写

       Debug.Log(str.ToLower());

 

Static

 

Static修饰的类的静态方法

 classPersion {

   int age;

   //处理逻辑函数Math.sin,Math.cos

   //没有对象实例,就无法访问对象的数据成员和调用成员函数

    public sta tic void test() {

       Debug.Log("Persion test");

    }

   public void normal() {

       this.age = 0;  

    }

}

public class game_scene : MonoBehaviour {

void Start (){

Persion.test();

}

}

 

Static 修饰的静态变量

class Persion{

public  static  float  pi = 3.14f;

}

public class game_scene : MonoBehaviour {

void Start (){

Persion.pi = 3.14f;//不需要实力就可以直接访问

 }

Const readonly

Const 

//一旦由const定义就无法修改,只能访问

   public  (static)  const  int  text_const= 3;

//每一个实例,都会有一个readonly变量

   //readonly的变量,还有一次修改的机会,

   //对象构造的时候构造函数里边

   public readonly int test_readonly = 4;

   public Person(){

       this.test_readonly=5;

    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值