Beispiel #1
0
        private static void ShowList()
        {
            List <string> list = new List <string>()
            {
                "friend", "boy", "girl", "HelloKitty", "environment", "idiot", "collection", "jerk", "abstract"
            };

            //Add(), Remove()
            list.Add("dog");
            if (list.Contains("HelloKitty"))
            {
                list.Remove("HelloKitty");
            }

            //Sort()
            list.Sort();
            list.Sort(new StringComparer());

            //RemoveAt()
            while (list.Count() > 5)
            {
                list.RemoveAt(list.Count() - 1);
            }

            //BinarySearch()  Insert()
            int search = list.BinarySearch("zippo");

            if (search < 0)
            {
                list.Insert(~search, "zippo");
            }

            //findall()
            List <string> ContainO = list.FindAll(item => item.Contains("o"));

            //Test
            List <object> Olist = new List <object>()
            {
                "a", "b", 1, 2
            };
            object member = Olist[2];

            member = 9;
            PatentData.Print <object>(Olist);
            Console.WriteLine(Environment.NewLine);

            PatentData.Print <string>(ContainO);
        }
Beispiel #2
0
        private static void ShowLinkedList()
        {
            LinkedList <string> linklist = new LinkedList <string>();

            linklist.AddFirst("First");
            linklist.AddLast("Last");
            LinkedListNode <string> FirstNode = linklist.First;
            LinkedListNode <string> LastNode  = linklist.Last;

            linklist.AddAfter(FirstNode, "1");
            linklist.AddAfter(LastNode, "TrueLast");

            linklist.RemoveFirst();

            PatentData.Print <string>(linklist);
        }