赞
踩
总目录
C# 语法总目录
List有ArrayList和LinkedList
//ArrayList
//ArrayList
ArrayList arrList = new ArrayList();
arrList.Add("andy");
arrList.Add("sandy");
arrList.Add("sunny");
arrList.RemoveAt(1);
arrList.Reverse();
arrList.Insert(1, "tom");
arrList.InsertRange(0, new[] {"times","jerry"});
foreach (var item in arrList)
{
Console.WriteLine(item);
}
/*
times
jerry
sunny
tom
andy
*/
//LinkList
//LinkList
LinkedList<string> linkArr = new LinkedList<string>();
//从头部加入
linkArr.AddFirst("andy");
linkArr.AddFirst("sandy");
linkArr.AddFirst("sunny");
//sunny
//sandy
//andy
//从尾部加入
linkArr.AddLast("tom");
linkArr.AddLast("jerry");
/*
sunny
sandy
andy
tom
jerry
*/
//在顺数第三个位置添加元素
linkArr.AddAfter(linkArr.First.Next, "get");
//在倒数第三个位置添加元素
linkArr.AddBefore(linkArr.Last.Previous, "give");
foreach (var item in linkArr)
{
Console.WriteLine(item);
}
/*
sunny
sandy
get
andy
give
tom
jerry
*/
队列,先进先出
Queue<string> queue = new Queue<string>();
queue.Enqueue("tom");
queue.Enqueue("jerry");
queue.Enqueue("times");
string deTemp = queue.Dequeue();
Console.WriteLine("dequeue ele is "+deTemp);
Console.WriteLine(queue.Count);
Console.WriteLine(queue.Contains("tom"));
//给容器瘦身
queue.TrimExcess();
string[] strArr = queue.ToArray();
foreach (var item in strArr)
{
Console.WriteLine(item);
}
/*
dequeue ele is tom
2
False
jerry
times
*/
总目录
C# 语法总目录
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。