示例#1
0
        // Sort the private list in the model
        // Supply a Comparison delegate to customize Sort(Comparison<T>)
        public void SortPersons(string title, Comparison <MyPerson> c)
        {
            Console.WriteLine("\n\t DemoCollections.SortPersons()...");

            Console.WriteLine($"{title} {DemoCollectionsPersonsList.Count} elements in list.");
            DemoCollectionsPersonsList.Sort(c);   // sort using supplied Comparison<T> delegate
            DemoCollectionsPersonsList.ForEach(person => Console.Write($"{person}; "));
            //foreach (var person in DemoCollectionsPersons) Console.Write($"{person}, ");
            Console.WriteLine($" First: {DemoCollectionsPersonsList[0]} Last: {DemoCollectionsPersonsList[DemoCollectionsPersonsList.Count - 1]}");

            Console.WriteLine("\n\t DemoCollections.SortPersons()... done!");
        }
示例#2
0
        public void UpdatePersons()
        {
            Console.WriteLine("\n\t DemoCollections.UpdatePersons()... ");
            int offset = 100;

            Console.WriteLine($"{DemoCollectionsPersonsList.Count} persons in list.");
            DemoCollectionsPersonsList.ForEach(person => Console.Write($"{person}; "));
            Console.WriteLine($"\nAge by {offset} years:");
            DemoCollectionsPersonsList.ForEach(p => p.Age = p.Age + offset);
            DemoCollectionsPersonsList.ForEach(person => Console.Write($"{person}; "));

            Console.WriteLine("\n\t DemoCollections.UpdatePersons()... done!");
        }