c# 中的arrlist queue HashtableTest SortedList stack 的用法
解决方案 »
- asp.net web跳转到别的站点的网页怎么隐藏传值(看详细)
- URLRwrite
- 什么意思,正则表达式 "^[\d]([\d]{1,11}\+{1}){1,11}[\d]{1,11}$|^[\d]([\d]+(%2b)){1,1
- 文本框搜索提示
- ASP.net(C#)读取ACCESS数据库的写法
- 求助:关于TreeView
- 最后20分了,问一个最ben笨的问题:
- 怎样在SQL语句里批量传入参数?
- 定义时加“new”和不加“new”有什么区别
- 各位高手,救命呀!关于datevgrid编辑时使用dropdownlist控件!!!???????????
- DropDownList的一个小问题。。。。!!!!!!!!!!!
- 寻求 js动态显示城市的天气预报
http://msdn.microsoft.com/zh-cn/library/system.collections.arraylist(VS.80).aspx
Queue
http://msdn.microsoft.com/zh-cn/library/system.collections.queue.aspx
HashTable
http://msdn.microsoft.com/zh-cn/library/system.collections.hashtable(VS.80).aspx
SortedList
http://msdn.microsoft.com/zh-cn/library/system.collections.sortedlist(VS.80).aspx
Stack
http://msdn.microsoft.com/zh-cn/library/3278tedw.aspx
My blog
http://www.cnblogs.com/Peter-Zhang/articles/1777235.html
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace arraylist
{
class Program
{
static void Main(string[] args)
{
ArrayList arrlist = new ArrayList();
arrlist.Add("苹果");//增加
arrlist.Add("香焦");
arrlist.Add("葡萄");
foreach (int n in new int[3] { 0, 1, 2 })
{
arrlist.Add(n);
}
arrlist.Remove(0);//移除值为0的数
arrlist.RemoveAt(3);//移除索引为3的数
arrlist.Insert(1, "apple");//在指定索引处插入数
for (int i = 0; i < arrlist.Count; i++)
{
Console.WriteLine(arrlist);
}
Console.Read();
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace HashtableTest
{
class Program
{
static void Main(string[] args)
{
Hashtable student = new Hashtable();
student.Add("001","Tom");//增加 student.Add("002", "Lily");
student.Add("003", "Jime");
student.Add("004", "Lucy");
foreach (DictionaryEntry element in student)
{
string di =element.Key .ToString ();
string name = element .Value .ToString ();
Console.WriteLine("学生的ID:{0} 学生的姓名 {1}",di,name );
}
student.Remove("003");
Console.WriteLine("删后遍历队:");
foreach (DictionaryEntry element in student)
{
string di = element.Key.ToString();
string name = element.Value.ToString();
Console.WriteLine("学生的ID:{0} 学生的姓名 {1}", di, name);
}
Console.Read();
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace queueTest
{
class Program
{
static void Main(string[] args)
{
Queue queue = new Queue();
for (int i = 0; i < 6; i++)
{
queue.Enqueue(i);
Console.WriteLine("{0}入队列", i);
}
Console.WriteLine("返回队开始的元素{0}", queue.Peek().ToString());
Console.WriteLine("遍历队:");
foreach (int n in queue)
{
Console.WriteLine(n );
}
while (queue.Count != 0)
{
int q = (int)queue.Dequeue();
Console.WriteLine("{0}出队", q);
}
Console.Read();
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace SortedListTest
{
class Program
{
static void Main(string[] args)
{
SortedList student = new SortedList();
student.Add("001","Lucy");
student.Add("002", "Lily");
student.Add("003", "Tom");
student.Add("004", "Jim");
foreach (DictionaryEntry n in student)
{
string id = n.Key.ToString();
string name = n.Value.ToString();
Console.WriteLine("学生的ID:{0} ,学生的姓名: {1}",id ,name );
}
student.Remove("003");
Console.WriteLine("删后的栈");
foreach (DictionaryEntry n in student)
{
string id = n.Key.ToString();
string name = n.Value.ToString();
Console.WriteLine("学生的ID:{0} ,学生的姓名: {1}", id, name);
}
Console.Read();
}
}
}using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace stacktest
{
class Program
{
static void Main(string[] args)
{
Stack stack = new Stack();
for (int i=0; i < 6; i++)
{
stack.Push(i);
}
Console.WriteLine("当前栈顶元素为:{0}",stack .Peek ().ToString());
Console.WriteLine("移出栈顶元素:{0}",stack .Pop ().ToString() );
Console.WriteLine("当前栈顶元素为:{0}", stack.Peek().ToString());
Console.WriteLine("遍历栈");
foreach (int i in stack)
{
Console.WriteLine(i);
}
while (stack.Count != 0)
{
int s = (int)stack.Pop();
Console.WriteLine("{0}出栈", s);
}
Console.Read ();
}
}
}