而要來依序取得裡面的資料時,foreach裡引用的架構和一般有點不同,主要是keyValuePair。
using UnityEngine; using System.Collections; using System.Collections.Generic; public class MainProcess : MonoBehaviour { private Dictionary<int, string> tempDictionary = new Dictionary<int, string>(); void Start () { tempDictionary.Add( 1, "XXX" ); tempDictionary.Add( 2, "YYY" ); tempDictionary.Add( 3, "ZZZ" ); foreach( KeyValuePair<int, string> x in tempDictionary ) { Debug.Log( x.Key + " = " + x.Value ); } } }
沒有留言:
張貼留言