unity 中利用引用关系做考试下系统(list和dictionary)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class xuhaitao : MonoBehaviour
{
    public static xuhaitao instance;
    public List<Person> jihe = new List<Person>();
    public Dictionary<string ,Person> dic = new Dictionary<string, Person>();
    private void Awake()
    {
        instance = this;


        Person p01 = new Person("xuhaitao",38);

        jihe.Add(p01);
        dic.Add(p01.name, p01);


        print(jihe[0] == p01);             //  true
        print(dic["xuhaitao"] == p01);     //  true


        p01.age = 99;
        print(jihe[0].age);                // 99
        print(dic["xuhaitao"].age);        // 99
    }
}

public class Person
{
    public string name;
    public int age;
    public Person(string namee,int agee)
    {
        name = namee;
        age = agee;
    }
}

 

FR:徐海涛(hunk Xu)
QQ技术交流群:386476712

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值