| 分類:[C#]
using System;
/// <summary> /// Dictionary クラスの項目。 /// </summary> internal class Item { public string key; public string value; public Item next;
public Item(string key, string value, Item next) { this.key = key; this.value = value; this.next = next; } }
/// <summary> /// 辞書クラス。 /// </summary> class Dictionary { Item head;
public Dictionary() { this.head = new Item(null, null, null); }
public string this[string key] { set { for(Item item = this.head.next; item != null; item =item.next) if(item.key == key) { item.value = value; return; } this.head.next = new Item(key, value, this.head.next); } get { for(Item item = this.head.next; item != null; item =item.next) if(item.key == key) return item.value; return null; } } }
class IndexerSample { static void Main() { Dictionary dic = new Dictionary();
dic["ハァ"] = "( ゚Д゚)?"; dic["ハァハァ"] = "(;´Д`)"; dic["ポカーン"] = "( ゚д゚)"; dic["オマエモナ"] = "(´∀`)";
Console.Write(dic["ハァハァ"]); } }
ソースコードはこちらからhttp://ufcpp.net/study/csharp/oo_indexer.html このコードのインデクサー部分がなにをしているのかわかりません・・・・ 特にnextの部分なんかは定義が足りないように見えてしまいます・・・ インデクサーはまだあまり慣れていないのでこれでもかというくらいこのコードに ついて教えていただけるとありがたいです。 |