Unity3d中Dictionary和KeyValuePair的使用

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

public class test : MonoBehaviour { void Start () { Dictionary<int,object> dict = new Dictionary<int,object> (); dict.Add (0,new Vector2(0,0)); dict.Add (1,new Vector2(1,1)); dict.Add (2,new Vector3(2,2)); dict.Add (3,"abcd"); foreach (KeyValuePair<int,object> pair in dict) { Debug.Log (pair.Key+", "+pair.Value); } //0, (0.0, 0.0) //1, (1.0, 1.0) //2, (2.0, 2.0, 0.0) //3, abcd } }
原文地址:https://www.cnblogs.com/kingBook/p/6008264.html