.NET中的数据结构
来源:互联网 发布:qq群淘宝客优惠劵软件 编辑:程序博客网 时间:2024/04/30 03:59
一 Array
class Program
...{
static void Main(string[] args)
...{
Employee[] arrRDCenter = new Employee[4];
arrRDCenter[0] = new Employee("qiuwh", "rd");
arrRDCenter[1] = new Employee("yuanlh", "rd");
arrRDCenter[2] = new Employee("hongzq", "rd");
arrRDCenter[3] = new Employee("zhumd", "rd");
Console.WriteLine("Employees in arrRDCenter:");
foreach (Employee emp in arrRDCenter)
...{
if (emp != null) Console.WriteLine(emp.ToString());
}
Console.WriteLine();
Array Resize#region Array Resize
Array.Resize(ref arrRDCenter, 6);
arrRDCenter[4] = new Employee("luoyq", "rd");
arrRDCenter[5] = new Employee("liusj", "rd");
Console.WriteLine("Employees in arrRDCenter:");
foreach (Employee emp in arrRDCenter)
...{
if (emp != null) Console.WriteLine(emp.ToString());
}
#endregion
Console.ReadLine();
}
}
...{
static void Main(string[] args)
...{
Employee[] arrRDCenter = new Employee[4];
arrRDCenter[0] = new Employee("qiuwh", "rd");
arrRDCenter[1] = new Employee("yuanlh", "rd");
arrRDCenter[2] = new Employee("hongzq", "rd");
arrRDCenter[3] = new Employee("zhumd", "rd");
Console.WriteLine("Employees in arrRDCenter:");
foreach (Employee emp in arrRDCenter)
...{
if (emp != null) Console.WriteLine(emp.ToString());
}
Console.WriteLine();
Array Resize#region Array Resize
Array.Resize(ref arrRDCenter, 6);
arrRDCenter[4] = new Employee("luoyq", "rd");
arrRDCenter[5] = new Employee("liusj", "rd");
Console.WriteLine("Employees in arrRDCenter:");
foreach (Employee emp in arrRDCenter)
...{
if (emp != null) Console.WriteLine(emp.ToString());
}
#endregion
Console.ReadLine();
}
}
二 ArrayList
class Program
...{
static void Main(string[] args)
...{
ArrayList arrRDCenter = new ArrayList();
arrRDCenter.Add(new Employee("qiuwh", "rd"));
arrRDCenter.Add(new Employee("yuanlh", "rd"));
arrRDCenter.Add(new Employee("hongzq", "rd"));
arrRDCenter.Add(new Employee("zhumd", "rd"));
Console.WriteLine("Employees in arrRDCenter:");
foreach (Employee emp in arrRDCenter)
...{
if (emp != null) Console.WriteLine(emp.ToString());
}
Console.WriteLine();
Employee emp1 = new Employee("luoyq", "rd");
Employee emp2 = new Employee("liusj", "rd");
arrRDCenter.Add(emp1);
arrRDCenter.Add(emp2);
arrRDCenter.Remove(emp1);
Console.WriteLine("Employees in arrRDCenter:");
foreach (Employee emp in arrRDCenter)
...{
if (emp != null) Console.WriteLine(emp.ToString());
}
Console.ReadLine();
}
}
...{
static void Main(string[] args)
...{
ArrayList arrRDCenter = new ArrayList();
arrRDCenter.Add(new Employee("qiuwh", "rd"));
arrRDCenter.Add(new Employee("yuanlh", "rd"));
arrRDCenter.Add(new Employee("hongzq", "rd"));
arrRDCenter.Add(new Employee("zhumd", "rd"));
Console.WriteLine("Employees in arrRDCenter:");
foreach (Employee emp in arrRDCenter)
...{
if (emp != null) Console.WriteLine(emp.ToString());
}
Console.WriteLine();
Employee emp1 = new Employee("luoyq", "rd");
Employee emp2 = new Employee("liusj", "rd");
arrRDCenter.Add(emp1);
arrRDCenter.Add(emp2);
arrRDCenter.Remove(emp1);
Console.WriteLine("Employees in arrRDCenter:");
foreach (Employee emp in arrRDCenter)
...{
if (emp != null) Console.WriteLine(emp.ToString());
}
Console.ReadLine();
}
}
三 GenericList
class Program
...{
static void Main(string[] args)
...{
//ListDemo();
ArrayListDemo();
Console.ReadLine();
}
static void ListDemo()
...{
List<Employee> RDCenter = new List<Employee>();
RDCenter.Add(new Employee("qiuwh", "rd"));
RDCenter.Add(new Employee("yuanlh", "rd"));
//RDCenter.Add("zhumd");
foreach (Employee emp in RDCenter)
...{
if (emp != null) Console.WriteLine(emp.ToString());
}
}
static void ArrayListDemo()
...{
ArrayList RDCenter = new ArrayList();
RDCenter.Add(new Employee("qiuwh", "rd"));
RDCenter.Add(new Employee("yuanlh", "rd"));
RDCenter.Add("zhumd");
foreach (Employee emp in RDCenter)
...{
if (emp != null) Console.WriteLine(emp.ToString());
}
}
}
...{
static void Main(string[] args)
...{
//ListDemo();
ArrayListDemo();
Console.ReadLine();
}
static void ListDemo()
...{
List<Employee> RDCenter = new List<Employee>();
RDCenter.Add(new Employee("qiuwh", "rd"));
RDCenter.Add(new Employee("yuanlh", "rd"));
//RDCenter.Add("zhumd");
foreach (Employee emp in RDCenter)
...{
if (emp != null) Console.WriteLine(emp.ToString());
}
}
static void ArrayListDemo()
...{
ArrayList RDCenter = new ArrayList();
RDCenter.Add(new Employee("qiuwh", "rd"));
RDCenter.Add(new Employee("yuanlh", "rd"));
RDCenter.Add("zhumd");
foreach (Employee emp in RDCenter)
...{
if (emp != null) Console.WriteLine(emp.ToString());
}
}
}
另附Employee类
class Employee
...{
public string Name;
public string Dept;
public Employee(string name, string dept)
...{
this.Name = name;
this.Dept = dept;
}
public override string ToString()
...{
return string.Format("Name:{0}, Dept:{1}", this.Name, this.Dept);
}
}
}
...{
public string Name;
public string Dept;
public Employee(string name, string dept)
...{
this.Name = name;
this.Dept = dept;
}
public override string ToString()
...{
return string.Format("Name:{0}, Dept:{1}", this.Name, this.Dept);
}
}
}
四 HashTable
class Program
...{
static void Main(string[] args)
...{
Hashtable currencies = new Hashtable();
currencies.Add("PRC", "Yuan");
currencies.Add("US", "Dollar");
currencies.Add("Japan", "Yen");
currencies.Add("France", "Euro");
Console.WriteLine("PRC Currency: {0}", currencies["PRC"]);
Console.WriteLine("France Currency: {0}", currencies["France"]);
foreach (DictionaryEntry de in currencies)
...{
Console.WriteLine(de.Key + " = " + de.Value);
}
Console.ReadLine();
}
}
...{
static void Main(string[] args)
...{
Hashtable currencies = new Hashtable();
currencies.Add("PRC", "Yuan");
currencies.Add("US", "Dollar");
currencies.Add("Japan", "Yen");
currencies.Add("France", "Euro");
Console.WriteLine("PRC Currency: {0}", currencies["PRC"]);
Console.WriteLine("France Currency: {0}", currencies["France"]);
foreach (DictionaryEntry de in currencies)
...{
Console.WriteLine(de.Key + " = " + de.Value);
}
Console.ReadLine();
}
}
五 Stack and Queue
class Program
...{
static void Main(string[] args)
...{
//StackDemo();
QueueDemo();
Console.ReadLine();
}
static void StackDemo()
...{
Stack stack = new Stack();
stack.Push("1");
stack.Push("2");
stack.Push("3");
stack.Push("4");
stack.Push("5");
Console.WriteLine("topmost element: " + stack.Peek());
Console.WriteLine("total elements: " + stack.Count);
while (stack.Count > 0)
...{
Console.Write(" " + stack.Pop());
}
}
static void QueueDemo()
...{
Queue queue = new Queue();
queue.Enqueue("1");
queue.Enqueue("2");
queue.Enqueue("3");
queue.Enqueue("4");
queue.Enqueue("5");
Console.WriteLine("topmost element: " + queue.Peek());
Console.WriteLine("total elements: " + queue.Count);
while (queue.Count > 0)
...{
Console.Write(" " + queue.Dequeue());
}
}
}
...{
static void Main(string[] args)
...{
//StackDemo();
QueueDemo();
Console.ReadLine();
}
static void StackDemo()
...{
Stack stack = new Stack();
stack.Push("1");
stack.Push("2");
stack.Push("3");
stack.Push("4");
stack.Push("5");
Console.WriteLine("topmost element: " + stack.Peek());
Console.WriteLine("total elements: " + stack.Count);
while (stack.Count > 0)
...{
Console.Write(" " + stack.Pop());
}
}
static void QueueDemo()
...{
Queue queue = new Queue();
queue.Enqueue("1");
queue.Enqueue("2");
queue.Enqueue("3");
queue.Enqueue("4");
queue.Enqueue("5");
Console.WriteLine("topmost element: " + queue.Peek());
Console.WriteLine("total elements: " + queue.Count);
while (queue.Count > 0)
...{
Console.Write(" " + queue.Dequeue());
}
}
}
- .NET中的数据结构
- 数据结构在.net反流程混淆中的应用
- .NET数据结构
- net-snmp transport数据结构
- VB中的数据结构使用
- GIS中的栅格数据结构
- oracle 中的数据结构
- 数据结构绪论中的几道题
- Java中的数据结构
- Java中的数据结构
- C# 中的数据结构
- 数据结构中的maze问题
- VB中的数据结构使用
- Java中的数据结构
- QT中的常用数据结构
- python 中的常见数据结构
- Java数据结构中的排序
- perl中的数据结构
- 用VS2005写的C++程序能在未安装VS2005的机器上直接运行吗?
- .NET中的常用接口
- 初学Ajax
- 看《夜宴》
- 用Python来烹调大餐
- .NET中的数据结构
- jfreechart生成Multiple Pie Chart
- .NET 泛型的特殊使用
- nullable generic structure
- CAPXOUS AutoComplete 1.2.5 自动完成 AJAX 破解版 注册版
- 关于参加考试的一点想法以及我的系分经历
- 婚礼上,新郎的一段精彩表白
- .net 服务器端生成alert/confim 消息
- gc的用法