using System;
//使用集合时要先引入命名空间
//使用非泛型时引用的命名空间
using System.Collections;
//使用泛型时引用的命名空间
using System.Collections.Generic;namespace Application
{
class MainClass
{
public static void Main(string[] args)
{
//栈
int[] arr = {23, 34, 1, 3 };
Stack stack = new Stack(arr);
//入栈
stack.Push("string");
//出栈 后进先出;
string str = stack.Pop() as string;
Console.WriteLine(str);
//元素个数;
int a = stack.Count;
Console.WriteLine(a);
//获取栈顶元素;但是不移除
object b = stack.Peek();
Console.WriteLine(b);
//是否包含;
bool c = stack.Contains("string");
Console.WriteLine(c);
//队列
Queue queue = new Queue(arr);
//入队
queue.Enqueue("string");
//加个空的值
queue.Enqueue(null);
//出队
//object obj = queue.Dequeue();
//Console.WriteLine(obj);
//queue.Clear();
Console.WriteLine(queue.Count);
object[] array = queue.ToArray();
//遍历
foreach (object i in queue)
{
Console.Write(i + " ");
}
//泛型栈和队列
Stack<int> stack_1 = new Stack<int>();
Queue<string> queue_2 = new Queue<string>();
stack_1.Push(12);
queue_2.Enqueue("sb");
}
}
}