C#集合

using System;
using System.Collections;
using System.Collections.Generic;
using static System.Console;

//集合

namespace lwm
{
    class Program
    {
        static void Main()
        {
            //1.列表 容量0 -> 4 -> 8 ->16
            var intList = new List<int>();
            intList.Capacity = 20;
            //WriteLine(intList.Count);
            intList.TrimExcess();

            intList.Add(1);
            intList.AddRange(new int[]{2,3,4});
            
            for (int i = 0; i < intList.Count; ++i)
            {
                WriteLine(intList[i]);
            }

            WriteLine();

            intList.RemoveAt(0);
            intList.Remove(3);

            foreach (var i in intList)
            {
                WriteLine(i);
            }

            intList.IndexOf(4);

            intList.Sort();

            //2.队列
            var q = new Queue<double>();

            //3.栈
            var s = new Stack<double>();

            //4.双向链表
            var linkList = new LinkedList<int>();

            //5.有序列表 基于键排序 //元素类型KeyValuePair<TKey, TValue>
            var sList = new SortedList<int, string>();

            foreach (int i in sList.Keys)
            { }
            foreach (string s1 in sList.Values)
            { }

            //6.字典
            var dict = new Dictionary<int, string>();
            var sdict = new SortedDictionary<int, string>();

            //7.集 不能重复
            var hset = new HashSet<int>();
            var sset = new SortedSet<int>();


        }

    }

}

posted @ 2018-10-26 16:14  xslwm  阅读(146)  评论(0编辑  收藏  举报