using UnityEngine;
using System.Collections;
class Item{
public int no;
public string name;
public int price;
}
public class chap10_10 : MonoBehaviour {
// Use this for initialization
void Start () {
Hashtable ht = new Hashtable();
Item a = new Item();
//string text = "2014 Asian Game 2014 World Cup " + " 2014 LOL Game Asian Cup";
string[] ItemList = {"1, HP POTION LV1, 1000", "2, MP POTION LV1, 1000",
"3, HP POTION LV2, 5000", "3, MP POTION LV2, 5000"} ;
char[] sep = {','} ;
foreach(string data in ItemList){
print (data);
string[] tokens = data.Split(sep);
//print(tokens[0]);
//print(tokens[1]);
//print(tokens[2]);
Item item = new Item();
item.no = int.Parse(tokens[0]);
item.name = tokens[1];
item.price = int.Parse(tokens[2]);
ht[item.no] = item;
}
Item item1 = ht[1] as Item;
if(ht.ContainsKey(1))
item1 = (Item)ht[1];
if(ht.ContainsValue(item1))
print ("item1 Exist");
foreach(Item item in ht.Values){
print (string.Format("Item[{0}] = [{1}], price = {2} ", item.no, item.name, item.price));
}
}
// Update is called once per frame
void Update () {
}
}
'Computer Language > 유니티' 카테고리의 다른 글
해쉬 테이블 DictionaryEntry 사용 예제 (0) | 2014.05.20 |
---|---|
상태 이상시 잘쓰는 비트 연산 (0) | 2014.05.20 |
문자 짜르기 해쉬 테이블 사용 (0) | 2014.05.20 |
해쉬 테이블 -> 어레이 리스트 (0) | 2014.05.20 |
큐를 이용한 총알 놀이 invoke sendmessage transform (0) | 2014.05.20 |