namespace RegC { class Program { static void Main(string[] args) { Session session = new Session(); session["userName"] = "jcrjia"; Console.Write(session["userName"]); Console.Read(); } } class Session { private Hashtable _hashtable = new Hashtable(); public object this[object index] { get { return _hashtable[index]; } set { _hashtable.Add(index,value); } } } }
public void Add(string name, object value) { this._container[name] = value; } public object this[string name] { get { return this._container[name]; } set { this._container[name] = value; } } public object this[int index] { get { return this._container[index]; } set { this._container[index] = value; } }