C#的一些整理

继承:会继承基类的所有对象,但是私有的无法访问,这就是体现了封装性!基类保护自己的成员,对面给你一个public函数,让你获得,但是成员的处理都封装起来

    class A {
        private int a = 1;
        public int  GetA()
        {
            return a;
        }
        public A() {
            Console.WriteLine("a ");
        }
    }
    class B : A {
       public B() {
            Console.WriteLine("b");
        }
    }
Main函数
  B b = new B();
            Console.WriteLine( b.GetA());
            Console.ReadKey();

先跑基类的构造函数,然后是子类, 私有成员,类外通过类的对象无法访问,只能让类对外提供接口

2

异步加载场景,unity使用中间过渡场景,在过渡场景加载比较大的场景

using UnityEngine;
using System.Collections;

public class LoadingAsy : MonoBehaviour {
    public UILabel _text;
    // Use this for initialization
    AsyncOperation asy;
    int Frame_rate = 0;
	void Start () {
        asy=Application.LoadLevelAsync("Fish");
        asy.allowSceneActivation = false;  //加载到90%不让他自动进入
	}

    // Update is called once per frame
    void Update () {
        Frame_rate++;
        if (Frame_rate > 10)
        {
            Frame_rate = 0;
            Debug.Log("rate");//  每10帧输出一次
        }
        _text.text = asy.progress * 100 + "%";// 场景太快,瞬间进去了
	}
}

3 get set方法

namespace TestWhile
{
    class TestGetSetFunc
    {
        public int  Id{get;set;}
    }
}

            TestGetSetFunc testGet = new TestGetSetFunc();
            testGet.Id = 122;
            Console.WriteLine(testGet.Id);
            Console.ReadKey();

getset方法  ,定义了一个内在变量,直接给其赋值,直接取出变量,通过类似函数指针的Id方法


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值