博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C#集合类使用范例
阅读量:7061 次
发布时间:2019-06-28

本文共 1409 字,大约阅读时间需要 4 分钟。

 //Dictionary

System.Collections.DictionaryEntry dic=new System.Collections.DictionaryEntry("key1","value1");
//ArrayList
System.Collections.ArrayList list=new System.Collections.ArrayList();
list.Add(1);//添加数据
list.Add(2);
for(int i=0;i<list.Count;i++)
{
System.Console.WriteLine(list[i]);//取出数据
}
//HashTable
System.Collections.Hashtable table=new System.Collections.Hashtable();
table.Add("table1",1);//添加数据
table.Add("table2",2);
System.Collections.IDictionaryEnumerator d=table.GetEnumerator();//获取迭代器
while(d.MoveNext())
{
System.Console.WriteLine(d.Entry.Key);//通过迭代器获取数据
}
System.Console.WriteLine(table["table1"]);//直接读取数据
//Queue
System.Collections.Queue queue=new System.Collections.Queue();
queue.Enqueue(1);//入队
queue.Enqueue(2);
System.Console.WriteLine(queue.Peek());//Queue.Peek()方法,取出队顶数据但不出队
while(queue.Count>0)
{
System.Console.WriteLine(queue.Dequeue());//出队
}
//SortedList
System.Collections.SortedList list=new System.Collections.SortedList();
list.Add("key2",2);//添加数据
list.Add("key1",1);
for(int i=0;i<list.Count;i++)
{
//打印输出,可以看出数据被排序了
System.Console.WriteLine(list.GetKey(i));//获取关键字
}
//Stack
System.Collections.Stack stack=new System.Collections.Stack();
stack.Push(1);//入栈
stack.Push(2);
System.Console.WriteLine(stack.Peek());//Stack.Peek()方法,取出栈顶数据但不出栈
while(stack.Count>0)
{
System.Console.WriteLine(stack.Pop());//出栈
}

转载于:https://www.cnblogs.com/qxoffice2008/p/3907709.html

你可能感兴趣的文章
thinkphp 跨模块调用配置文件信息
查看>>
nohup命令在后台自动执行程序
查看>>
MAVEN项目后 jar包无法发布到eclipse的web服务器
查看>>
选择结构与循环结构
查看>>
Linux系统生成随机密码的10种方法
查看>>
puppet初体验
查看>>
oracle安装前环境检查
查看>>
ansible出错
查看>>
linux内核中的信号机制--一个简单的例子
查看>>
【Java】File.createTempFile创建临时文件
查看>>
ldap bdb_db_open 错误解决办法
查看>>
根据菜单查找构建的窗体、流程、报表
查看>>
判断某年是否是闰年
查看>>
初探 C++ 标准库(二十六)
查看>>
安装SP3后不能进入系统的办法
查看>>
20150905日课程作业(计划任务mail,at,cron,)
查看>>
shell训练营Day15
查看>>
MySQL常用语句命令
查看>>
关于字符串的一些操作
查看>>
bootstrap-导航(垂直堆叠带分隔线的导航)
查看>>