Queue(队列)是先进先出的集合; Stack(堆栈)是后进先出的集合.
Queue 的主要成员:
/* 属性 */ Count //元素数 /* 方法 */ Clear() //清空 Contains() //是否包含 Dequeue() //出列 Enqueue() //入列 Peek() //获取将要出列的
Stack 的主要成员:
/* 属性 */ Count // /* 方法 */ Clear() // Contains() // Peek() //获取将要出栈的 Pop() //出栈 Push() //压栈
Queue 测试:
protected void Button1_Click(object sender, EventArgs e) { Queue queue = new Queue(); queue.Enqueue("abc"); queue.Enqueue(123); queue.Enqueue(true); string str = ""; foreach (object obj in queue) { str += obj.ToString() + "; "; } TextBox1.Text = str; //abc; 123; True; } protected void Button2_Click(object sender, EventArgs e) { Queue queue = new Queue(); queue.Enqueue("AA"); queue.Enqueue("BB"); queue.Enqueue("CC"); queue.Enqueue("DD"); string s1 = queue.Dequeue().ToString(); //AA int n1 = queue.Count; //3 string s2 = queue.Peek().ToString(); //BB int n2 = queue.Count; //3 string s3 = queue.Dequeue().ToString(); //BB int n3 = queue.Count; //2 queue.Clear(); int n4 = queue.Count; //0 TextBox1.Text = string.Concat(s1, "\n", n1, "\n", s2, "\n", n2, "\n", s3, "\n", n3, "\n", n4); }
Stack 测试:
protected void Button1_Click(object sender, EventArgs e) { Stack stack = new Stack(); stack.Push("AA"); stack.Push("BB"); stack.Push("CC"); string s1 = stack.Pop().ToString(); //CC stack.Push("DD"); string s2 = stack.Pop().ToString(); //DD string s3 = stack.Peek().ToString(); //BB string s4 = stack.Pop().ToString(); //BB int n = stack.Count; //1 bool b = stack.Contains("AA"); //True TextBox1.Text = string.Concat(s1, "\n", s2, "\n", s3, "\n", s4, "\n", n, "\n", b); }
我们用的比较多的非泛型集合类主要有ArrayList类和HashTable类。我们经常用HashTable来存储将要写入到数据库或者返回的信息,在这之间要不断的进行类型的转化,增加了系统装箱和拆箱的负担,14:31:45,例如我们需要在电子…
获取服务器的IP地址方法以DNS法较为简单实用,如下:usingSystem.Net;privatevoidButtonIP_Click(objectsender,System.EventArgse){System.Net.IPAddres…
1、SQL语句分类1.1、分类方法及类型1.2、数据定义语言1.3、数据操纵语言1.4、其它语句2、动态SQL理论2.1、动态SQL的用途2.2、动态SQL的语法2.3、绑定变量3、动态SQL实战3.1、封装执行DML的通用存储过程3.2、…
简介在C#中,Dictionary提供快速的基于兼职的元素查找。当你有很多元素的时候可以使用它。它包含在System.Collections.Generic名空间中。在使用前,你必须声明它的键类型和值类型。详细说明必须包含名空间System…
就像WebApi接口可以对入参进行验证,避免用户传入非法的或者不符合我们预期的参数一样,选项也可以对配置源的内容进行验证,避免配置中的值与选项类中的属性不对应或者不满足预期,毕竟大部分配置都是通过字符串的方式,验证是很有必要的。1.注解…
1、动态数组:ArrayList主要方法:Add、AddRange、RemoveAt、Remove2、队列:Queue主要方法:Enqueue入队列、Dequeue出队列、Peek返回Queue开始处的对象但不删除3、栈:Stack后进先出…
usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Data;usingSystem.Data.SqlClient;usingSystem.Con…
提供了针对可扩展的提供程序模型的基实现。命名空间:System.Configuration.Provider程序集:System.Configuration(在System.Configuration.dll中)C#publicabstra…