HashText的应用

来源:互联网 发布:阿里云推荐码申请 编辑:程序博客网 时间:2024/06/16 18:12
 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        #region hashtable
        //Person zhang = new Person("张","三");
        //Person li = new Person("李", "四");
        //Person wang = new Person("王", "五");
        //Hashtable hash = new Hashtable();
        //hash.Add("zhang", zhang);
        //hash.Add("li", li);
        //hash.Add("wang", wang);
        ////hashtable中存储的键值对使用了DictionaryEntry结构体
        ////所以遍历是需要使用DictionaryEntry结构
        //foreach (DictionaryEntry p in hash)
        //{
        //    Person pp = p.Value as Person;
        //    Response.Write(pp.FirstName + pp.LastName + "<br/>");
        //}
        //Response.Write("----------------<br/>");
        //foreach (Person p in hash.Values)  //Values为Person的集合
        //{
        //    Response.Write(p.FirstName + p.LastName + "<br/>");
        //}
        #endregion
        #region sortedlist
        //Person zhang = new Person("张", "三");
        //Person li = new Person("李", "四");
        //Person wang = new Person("王", "五");
        //SortedList list = new SortedList();
        //list.Add("d", zhang);
        //list.Add("b", li);
        //list.Add("c", wang);
        //int index = list.IndexOfKey("d");
        //Response.Write(index + "<br/>");
        //index = list.IndexOfValue(zhang);
        //Response.Write(index + "<br/>");
        //Person p = (Person)list.GetByIndex(index);
        //Person pp = (Person)list["d"];
        #endregion
        #region Queue
        //Queue qu = new Queue();
        //qu.Enqueue("hello ");
        //qu.Enqueue("world ");
        //qu.Enqueue("!");
        //int nums = qu.Count;
        ////随着Dequeue的调用,队列的数量会减少,所以在循环
        ////中不能使用qu.Count控制循环的次数
        //for (int i = 0; i < nums; i++)
        //    Response.Write(qu.Dequeue().ToString());
        //Response.Write("------------------<br/>");
       
        //foreach (string str in qu)
        //{
        //    Response.Write(str);
        //}
        #endregion

        #region statck
        //Stack sk = new Stack();
        //sk.Push("hello ");
        //sk.Push("world ");
        //sk.Push("!");

        //int nums = sk.Count;
        //for (int i = 0; i < nums; i++) //典型的后进先出结构
        //{
        //    Response.Write(sk.Pop().ToString());
        //}
        #endregion

        #region 强类型列表
        //Person zhang = new Person("张", "三");
        //Person li = new Person("李", "四");
        //Person wang = new Person("王", "五");

        ////ArrayList list = new ArrayList();
        ////list.Add(zhang);
        ////list.Add(li);
        ////list.Add(wang);

        ////强类型列表,personlist中只能存储Person对象,使用时可以避免强制转换时出错
        ////2.0版本以后引入泛型概念,使用泛型列表可以解决这些问题
        //PersonList list = new PersonList();
        //list.Add(zhang);
        //list.Add(li);
        //list.Add(wang);

        //for (int i = 0; i < list.Count; i++)
        //{
        //    Response.Write(list[i].FirstName + list[i].LastName + "<br/>");
        //}

        #endregion

        List<Person> list = new List<Person>();
        List<int> listi = new List<int>();
        List<string> lists = new List<string>();
       


    }
}

原创粉丝点击