ASP.net 中Queue,Stack,Hashtable,Sortlist一些簡單用法
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 Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Queue qu = new Queue();
qu.Enqueue("hello");
qu.Enqueue("word");
qu.Enqueue("!");
//foreach (string item in qu)
//{
// Response.Write(item);
//}
int m = qu.Count;
Response.Write("Queu先進先出:");
for (int i = 0; i < m; i++)
{
Response.Write(qu.Dequeue());
}
}
protected void Button2_Click(object sender, EventArgs e)
{
Stack st = new Stack();
st.Push(" hello");
st.Push(" World");
st.Push(" !");
// Response.Write(st.Peek());
// st.Pop();
Response.Write("Stack先進後出:");
//foreach (string item in st)
//{
// Response.Write(item);
//}
int mm = st.Count;
for (int i = 0; i < mm; i++)
{
Response.Write(st.Pop());
}
}
protected void Button3_Click(object sender, EventArgs e)
{
Person p = new Person("張", "三");
Person li = new Person("李", "四");
Person wang = new Person("王", "五");
Hashtable table = new Hashtable();
table.Add("z", p);
table.Add("li", li);
table.Add("wang", wang);
Response.Write("Hashtable通過三種遍歷方法進輸出的</br>");
foreach (DictionaryEntry item in table)
{
Person s = item.Value as Person;
Response.Write(s.FirstName + s.LastName + "</br>");
}
Response.Write("以上通過遍歷Hashtable轉換其型別後輸出</br>");
foreach (Person s in table.Values)
{
Response.Write(s.FirstName + s.LastName + "</br>");
}
Response.Write("以上通過遍歷Hashtable的Values轉換其型別後輸出</br>");
foreach (string s in table.Keys)
{
Person p5 = table[s] as Person;
Response.Write(p5.FirstName + p5.LastName + "</br>");
}
Response.Write("以上通過遍歷Hashtable的Keys轉換其型別後輸出" + "</br>");
}
protected void Button4_Click(object sender, EventArgs e)
{
Person p = new Person("張", "三");
Person li = new Person("李", "四");
Person wang = new Person("王", "五");
Hashtable table = new Hashtable();
table.Add("z", p);
table.Add("li", li);
table.Add("wang", wang);
ArrayList list = new ArrayList(table.Values); //ArrayList list = new ArrayList(table.Values);
foreach (Person item in list)
{
Response.Write(item.FirstName + item.LastName);
}
Response.Write("</br>以上是沒有排序過的</br>");
list.Sort();
foreach (Person item in list)
{
Response.Write(item.FirstName + item.LastName);
}
}
protected void Button5_Click(object sender, EventArgs e)
{
Person p = new Person("張", "三");
Person li = new Person("李", "四");
Person wang = new Person("王", "五");
SortedList sortlist = new SortedList();
sortlist.Add("z", li);
sortlist.Add("a", p);
sortlist.Add("b", wang);
Response.Write("李四,張三,王五</br>");
Response.Write("用sortlist之後自動按keys進行排序</br>");
foreach (Person item in sortlist.Values)
{
Response.Write(item.FirstName + item.LastName);
}
}
protected void Button6_Click(object sender, EventArgs e)
{
Person p = new Person("張", "三");
Person li = new Person("李", "四");
Person wang = new Person("王", "五");
SortedList sortlist = new SortedList();
sortlist.Add("z", li);
sortlist.Add("a", p);
sortlist.Add("b", wang);
int index = sortlist.IndexOfKey("z"); //得出z所有的索引
// Response.Write(index);
index = sortlist.IndexOfValue(li); //返回指定值所有的索引
//Response.Write(index);
Person p2 = (Person)sortlist.GetByIndex(index); //得到索引位置的值
Response.Write(p2.FirstName + p2.LastName);
}
}
相關文章
- c++中stack、queue、vector的用法C++
- C++【stack/queue】用法和例子C++
- C#中HashTable簡介和使用用法C#
- C# Queue Stack SortedListC#
- STL-queue&deque&stack
- ASP.NET Web Forms – Hashtable 物件簡介ASP.NETWebORM物件
- C++初階(stack+queue)C++
- ASP.NET MVC中簡單使用AutofacASP.NETMVC
- .NET原始碼Stack和Queue的實現原始碼
- C++中const的簡單用法C++
- fstream中ifstream和ofstream的簡單用法
- WITH的簡單用法
- Stack and Queue in JavaScript(Javascript中的資料結構之棧和佇列)JavaScript資料結構佇列
- asp.net中sitemap的簡單實用ASP.NET
- java集合類——Stack棧類與Queue佇列Java佇列
- 【資料結構】棧(Stack)和佇列(Queue)資料結構佇列
- Python中的selenium的簡單用法Python
- Promise的簡單用法Promise
- golang flag簡單用法Golang
- mysqldumpslow簡單用法MySql
- Leetcode SortListLeetCode
- Asp.net core中RedisMQ的簡單應用ASP.NETRedisMQ
- Hashtable簡介和使用
- 簡單介紹SQLserver中的declare變數用法SQLServer變數
- js迴圈中reduce的用法簡單介紹JS
- C++的Stack模板的簡單實現C++
- asp.net中關於雙引號和單引號的用法ASP.NET
- ASP.NET Core 中簡單Session登入校驗ASP.NETSession
- git-stash簡單用法Git
- Android Scroller簡單用法Android
- Android AsyncTask簡單用法Android
- 簡單介紹Python中異常處理用法Python
- javascript中的就加號+的用法簡單介紹JavaScript
- 【專案實戰】---SQLServer中case when的簡單用法SQLServer
- Python中那些簡單又好用的特性和用法Python
- Elastic Stack 簡介AST
- asp.net中形式的用法(原創)ASP.NET
- 資料結構分析及其實現(Stack、Queue、Tree、LinkedList)資料結構