当前位置: 首页>>代码示例>>C#>>正文


C# CustomList.Clear方法代码示例

本文整理汇总了C#中CustomList.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# CustomList.Clear方法的具体用法?C# CustomList.Clear怎么用?C# CustomList.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CustomList的用法示例。


在下文中一共展示了CustomList.Clear方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GivenListWithTwoItems_WhenClearingTheList_ThenTheCountOfTheListAreZero

 public void GivenListWithTwoItems_WhenClearingTheList_ThenTheCountOfTheListAreZero()
 {
     var list = new CustomList<int>();
     list.AddItem(1);
     list.AddItem(2);
     list.Clear();
     Assert.AreEqual(0, list.Count);
 }
开发者ID:RayLion,项目名称:nreality-journeyman-prework,代码行数:8,代码来源:CustomListFixture.cs

示例2: Main

    static void Main()
    {
        var doubleList = new CustomList<double>();

        doubleList.Add(5.5);
        doubleList.Add(6.9);
        doubleList.Add(6.4);
        doubleList.Add(6.7);
        doubleList.Add(5.6);

        int count = doubleList.Count;
        double max = doubleList.Max();
        double min = doubleList.Min();

        Console.WriteLine(doubleList);
        Console.WriteLine("Max: {0}; Min: {1}; Count: {2}", max, min, count);

        doubleList.Remove(6.4);
        doubleList.Remove(5.5);
        doubleList.RemoveAt(1);

        count = doubleList.Count;
        max = doubleList.Max();
        min = doubleList.Min();

        Console.WriteLine(doubleList);
        Console.WriteLine("Max: {0}; Min: {1} Count: {2}", max, min, count);

        doubleList.Clear();
        bool isEmpty = doubleList.isEmpty;
        Console.WriteLine(isEmpty);
        Console.WriteLine(doubleList);

        var stringList = new CustomList<string>();

        stringList.Add("Kircho");
        stringList.Add("Jecho");
        stringList.Add("Mecho");
        stringList.Add("Vulcho");

        bool jecho = stringList.Contais("Jecho");
        bool nencho = stringList.Contais("Nencho");

        string who = stringList.ElementOf(0);
        int index = stringList.IndexOf("Vulcho");
        string maxString = stringList.Max();

        Console.WriteLine(stringList);
        Console.WriteLine("jecho: {0} \nnencho: {1} \nElement of 0 index: {2} \nIndex of Vulcho: {3} \nMax: {4}"
            , jecho, nencho,who, index, maxString);

        string indexer = stringList[3];
        Console.WriteLine(indexer);
    }
开发者ID:alvelchev,项目名称:SoftUni,代码行数:54,代码来源:TestCustomList.cs

示例3: Main

        static void Main()
        {
            //Displaying program version
            var versionAttribute = typeof (CustomList<>).GetCustomAttributes(typeof (VersionAttribute), true);
            Console.WriteLine("Program version: {0}v\n", versionAttribute[0]);

            ComputerParts cpu = new ComputerParts("AMD Athlon II X3 3.20 Ghz", 90m);
            ComputerParts ram = new ComputerParts("Kingston HyperX 4x2 GB", 130m);
            ComputerParts motherboard = new ComputerParts("Asrock PRO X3", 50m);
            ComputerParts dvd = new ComputerParts("DVD-ROM LG DH18NS60", 21m);
            ComputerParts hdd = new ComputerParts("Samsung SSD 256 GB", 110m);
            
            CustomList<ComputerParts> parts = new CustomList<ComputerParts>();

            //Adding elements
            parts.Add(cpu);
            parts.Add(ram);
            parts.Add(motherboard);
            parts.Add(dvd);
            Console.WriteLine(parts);
            Console.WriteLine();

            //Accessing element by index
            Console.WriteLine(parts[2]);
            Console.WriteLine();
            
            //Removing element
            parts.Remove(3);
            Console.WriteLine(parts);
            Console.WriteLine();

            //Insert element
            parts.Insert(hdd, 2);
            Console.WriteLine(parts);
            Console.WriteLine();

            //Find element index by value
            Console.WriteLine("Motherboard index is {0}", parts.IndexOf(motherboard));
            Console.WriteLine();

            //Check if the list contains a value
            Console.WriteLine("Does the list contains HDD ? - {0}", parts.Contains(hdd));
            Console.WriteLine();

            //Cheking the minimum and maximum part by price
            Console.WriteLine("The cheapest part is: {0}", parts.Min());
            Console.WriteLine("The most expensive part is: {0}", parts.Max());
            Console.WriteLine();
            
            //Now we delete all the elements in the list
            parts.Clear();
            Console.WriteLine("We have a brand new list now :) {0}", parts);
        }
开发者ID:Dochko,项目名称:SoftUni,代码行数:53,代码来源:GenericListMain.cs

示例4: PrintInfoForBehavioralPatterns

        private static void PrintInfoForBehavioralPatterns()
        {
            // Chain Of Responsibility Test
            WriteTitleToConsole("Chain Of Responsibility Test");
            var random = new Random();
            var randomNumbers = Enumerable
                                .Repeat<Func<int, int, int>>(random.Next, 25)
                                .Select(rnd => rnd(0, 100))
                                .ToArray();
            Console.WriteLine(string.Join(",", randomNumbers));

            var algorithm = SortCombiner.GetSort();
            algorithm.ProcessSort(randomNumbers);
            Console.WriteLine(string.Join(",", randomNumbers));

            // C# Iterator Test
            WriteTitleToConsole("\nC# Iterator Test");
            var alphabet = new Alphabet("абвееегдежзийкабв");
            Console.WriteLine(string.Join(", ", alphabet));

            // Linked List Iterator Test
            WriteTitleToConsole("\nLinked List Iterator Test");
            var linkedList = new CustomList<int>();
            linkedList.Add(4);
            linkedList.Add(5);
            linkedList.Add(6);
            linkedList.Add(7);

            foreach (var item in linkedList)
            {
                Console.WriteLine(item);
            }

            linkedList.Clear();

            // Command Test
            WriteTitleToConsole("\nCommand Test");
            var engineer = new Engineer();
            engineer.Compute('+', 50);
            engineer.Compute('-', 10);
            engineer.Compute('*', 8);
            Console.WriteLine(engineer.Compute('/', 2));
            Console.WriteLine("Start Undo:");
            Console.WriteLine(engineer.Undo());
            Console.WriteLine(engineer.Undo());
            Console.WriteLine("Start Redo:");
            Console.WriteLine(engineer.Redo());
            Console.WriteLine(engineer.Redo());

            // Template Method Test
            WriteTitleToConsole("\nTemplate Method Test");
            var pepperoni = new Pepperoni();
            Console.WriteLine("Make pepperoni:");
            pepperoni.Make();

            var margherita = new Margherita();
            Console.WriteLine("\nMake margherita:");
            margherita.Make();

            // Strategy Test
            WriteTitleToConsole("\nStrategy Test");
            var general = new General(new List<IAttackStrategy>
                    {
                        new AirAttack(),
                        new LandAttack(),
                    });

            general.StartAttackOperation();

            // Observer Test
            WriteTitleToConsole("\nObserver Test");
            var school = RandomSchoolInitializer.getRandomSchool();
            var weakStudents = school.FoundAllWeakStudents().ToList();
            weakStudents.ForEach(student =>
            {
                student.Marks = new List<int>(student.Marks) { 2 };
            });

            // Mediator Test
            WriteTitleToConsole("\nMediator Test");
            var vivacom = new VivacomDispatcher();
            for (int i = 1; i <= 10; i++)
            {
                var client = new Client("Client" + (i).ToString(), i.ToString(), "Normal", DateTime.Now);
                vivacom.Register(client);
            }

            vivacom.Conect("4", "7");
            vivacom.Conect("5", "6");
            vivacom.Conect("1", "9");

            // Memento Test
            WriteTitleToConsole("\nMemento Test");
            var adder = new Adder("Bulgarian", 31, 23);
            var state = adder.getState();
            Console.WriteLine(adder.ToString());
            adder.Age += 11;
            adder.Length += 13.7;
            Console.WriteLine(adder.ToString());
            adder.RestorState(state);
//.........这里部分代码省略.........
开发者ID:Baruh,项目名称:Projects,代码行数:101,代码来源:Program.cs


注:本文中的CustomList.Clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。