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


C# GenericList.ToString方法代码示例

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


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

示例1: Main

 static void Main()
 {
     GenericList<Decimal> testGenList = new GenericList<decimal>();
     testGenList.Add(125.53M);
     testGenList.Add(123);
     testGenList.Add(100);
     testGenList.Add(1000);
     testGenList.Add(10000);
     Console.WriteLine(testGenList.ToString());
     Console.WriteLine(testGenList.Find(100));
     Console.WriteLine(testGenList.Access(1));
     Console.WriteLine(testGenList.Capacity);
     testGenList.Insert(0, 0);
     testGenList.Insert(5, 3);
     testGenList.Remove(testGenList.Count - 1);
     Console.WriteLine(testGenList.ToString());
     testGenList.Insert(16.16M, testGenList.Count - 1);
     testGenList.Insert(17.17M, testGenList.Count - 1);
     testGenList.Insert(18.18M, testGenList.Count - 1);
     testGenList.Insert(19.19M, testGenList.Count - 1);
     Console.WriteLine(testGenList.ToString());
     Console.WriteLine(testGenList.Max());
     testGenList.Remove(testGenList.Find(testGenList.Max()));
     Console.WriteLine(testGenList.ToString());
     Console.WriteLine(testGenList.Max());
     Console.WriteLine(testGenList.Min());
     testGenList.Remove(0);
     Console.WriteLine(testGenList.Min());
     testGenList.Clear();
     Console.WriteLine(testGenList.ToString());
 }
开发者ID:p0150n,项目名称:TelerikAcademy,代码行数:31,代码来源:GenericListTest.cs

示例2: Main

 static void Main()
 {
     GenericList<int> test = new GenericList<int>(10);
     for (int i = 0; i < test.Length; i++)
     {
         test.Add(i);
     }
     Console.WriteLine(test.ToString());
     test.Remove(9);
     Console.WriteLine(test.ToString());
     test.Insert(9, 9);
     Console.WriteLine(test);
     GenericList<int> newTest = new GenericList<int>(10);
     for (int i = 0; i < newTest.Length - 1; i++)
     {
         newTest.Add(i);
     }
     Console.WriteLine(newTest);
     newTest.Insert(10, 9);
     Console.WriteLine(newTest);
     newTest.Clear();
     Console.WriteLine(newTest);
     Console.WriteLine(test[3]);
     GenericList<string> stringTest = new GenericList<string>(10);
     for (int i = 0; i < stringTest.Length - 2; i++)
     {
         stringTest.Add(i.ToString());
     }
     Console.WriteLine(stringTest);
     stringTest.Add("huehuehueheuhe");
     Console.WriteLine(stringTest);
     stringTest.Insert("Teehee", 9);
     Console.WriteLine(stringTest);
 }
开发者ID:NasC0,项目名称:Telerik_Homework,代码行数:34,代码来源:GenericListTest.cs

示例3: Main

        static void Main()
        {
            GenericList<int> list = new GenericList<int>(5);
            StringBuilder result = new StringBuilder();
            list.Add(3);
            list.InsertAt(0, 2);
            list.InsertAt(0, 1);
            result.AppendLine(list.ToString());
            result.AppendLine(String.Format("Count: {0}", list.Count));

            result.AppendLine("--REMOVE AT INDEX 1--");
            list.RemoveAt(1);
            result.AppendLine(list.ToString());
            result.AppendLine(String.Format("Count: {0}", list.Count));

            result.AppendLine("     MIN: " + list.Min());
            result.AppendLine("     MAX: " + list.Max());

            result.AppendLine("-----INDEX OF 3-----");
            result.AppendLine(list.IndexOf(3).ToString());
            result.AppendLine("-----INDEX OF 2-----");
            result.AppendLine(list.IndexOf(2).ToString());

            result.AppendLine("-----CLEAR LIST-----");
            list.Clear();
            result.AppendLine(list.ToString());
            result.AppendLine(String.Format("Count: {0}", list.Count));

            Console.WriteLine(result);
        }
开发者ID:RuzmanovDev,项目名称:TelerikAcademy,代码行数:30,代码来源:Test.cs

示例4: Main

 static void Main()
 {
     try
     {
         GenericList<int> list = new GenericList<int>(5);
         list.Add(1);
         list.Add(2);
         list.Add(1);
         Console.Write("Add : ");
         Console.WriteLine(list.ToString());
         list.Remove(1);
         Console.Write("Remove : ");
         Console.WriteLine(list.ToString());
         list.Insert(3, 555);
         Console.Write("Insert : ");
         Console.WriteLine(list.ToString());
         Console.Write("Clear : ");
         list.ClearList();
         Console.WriteLine(list.ToString());
         Console.WriteLine("Searching element by its value");
         list.Add(1);
         list.Add(2);
         list.Add(1);
         list.Add(2);
         list.Insert(2, 3);
         Console.WriteLine(list.ToString());
         int indexOfElement = list.FindElement(1, 1);
         Console.WriteLine(indexOfElement);
     }
     catch (ArgumentOutOfRangeException exp)
     {
         Console.WriteLine("Error!");
         Console.WriteLine(exp);
     }
 }
开发者ID:naturalna,项目名称:OOPPrinciples,代码行数:35,代码来源:GenericExample.cs

示例5: Main

 static void Main(string[] args)
 {
     var listtt = new List<int>();
     GenericList<int> myList = new GenericList<int>(10);
     //ADD
     myList.Add(1);
     myList.Add(2);
     myList.Add(3);
     Console.WriteLine(myList.ToString());
     Console.WriteLine("Insert element");
     //INSERT AT GIVEN POSITION
     myList.Insert(3, 50);
     myList.Insert(3, 60);
     Console.WriteLine(myList.ToString());
     Console.WriteLine("Find element:");
     //FIND CERTAINT ELEMENT AT WHAT INDEXES EXISTS
     myList.Find(25);
     Console.WriteLine("Remove element:");
     //REMOVE AT CERTAIN INDEX
     myList.Remove(2);
     Console.WriteLine(myList.ToString());
     Console.WriteLine("Find maximum");
     //FIND MAX
     Console.WriteLine(myList.Max());
     Console.WriteLine("Find minimum");
     //FIND MIN
     Console.WriteLine(myList.Max());
     //CLEAR ALL
     Console.WriteLine("Clear all");
     myList.Clear();
     Console.WriteLine(myList.ToString());
 }
开发者ID:AYankova,项目名称:Telerik-Academy-HW,代码行数:32,代码来源:Test.cs

示例6: Main

        public static void Main()
        {
            GenericList<int> list = new GenericList<int>(4);

            Console.WriteLine("Add , auto-grow and ToString() test");
            Console.WriteLine();
            // Testing add method and auto-grow
            for (int i = 1; i <= 20; i++)
            {
                list.Add(i);
            }
            Console.WriteLine(list.ToString());
            AddSeparator();

            // Add 100 on position 5
            Console.WriteLine("Test insert at position (insert 100 on position 5)");
            Console.WriteLine();
            list.Add(100, 5);
            Console.WriteLine(list.ToString());
            AddSeparator();

            // Test min and max
            Console.WriteLine("Min --> {0}", list.Min());
            Console.WriteLine("Max --> {0}", list.Max());
            AddSeparator();

            // Indexer test
            Console.WriteLine("Indexer test:");
            Console.WriteLine("list[5] --> {0}", list[5]);
            AddSeparator();
        }
开发者ID:DareDev1l,项目名称:TelerikAcademy,代码行数:31,代码来源:GenericListTest.cs

示例7: Main

        static void Main()
        {
            GenericList<int> testList = new GenericList<int>(5);
            testList.Add(5);
            testList.Add(45);
            testList.Add(18);
            testList.Add(66);
            testList.Add(22);
            testList.Add(6);
            testList.Add(2);
            testList.Add(9);
            testList.Add(10);

            Console.WriteLine("tstList.Count ->{0}",testList.Count);
            Console.WriteLine(testList.ToString());

            testList.RemoveAt(3);
            Console.WriteLine("After removing an element:");
            Console.WriteLine("tstList.Count ->{0}", testList.Count);
            Console.WriteLine(testList.ToString());

            testList.InsertAt(3, 66);
            Console.WriteLine("After inserting an element:");
            Console.WriteLine("tstList.Count ->{0}", testList.Count);
            Console.WriteLine(testList.ToString());
            Console.WriteLine();
            Console.WriteLine("searching for element:");
            int position=testList.FindByValue(66);
            Console.WriteLine("The element is on position {0}", position);
            position = testList.Min();
            Console.WriteLine("The Min Element in list is {0}",position);
            position = testList.Max();
            Console.WriteLine("The Max Element in list is {0}",position);
        }
开发者ID:kicata,项目名称:OPP,代码行数:34,代码来源:TestGenericListClass.cs

示例8: Main

        static void Main()
        {
            string decorationLine = new string('-', 80);
            Console.Write(decorationLine);
            Console.WriteLine("***Creating and clearing lists of some type. Adding, removing, accessing, finding, inserting elements.***");
            Console.Write(decorationLine);

            Console.WriteLine("---Creating an empty list of strings---");
            GenericList<string> list = new GenericList<string>();
            Console.WriteLine("Empty list count: " + list.Count);
            Console.WriteLine("Empty list capacity: " + list.Capacity);

            Console.WriteLine("\n---Adding some elements to the list---");
            for (int count = 0; count < 16; count++)
            {
                list.Add("element " + (count + 1));
            }
            Console.WriteLine("The elements of the list are: " + list.ToString());
            Console.WriteLine("After adding some elements list count: " + list.Count);
            Console.WriteLine("After adding some elements list capacity: " + list.Capacity);

            Console.WriteLine("\n---Printing elements at specific indexes---");
            Console.WriteLine("Printing element with index 5: " + list[5]);
            Console.WriteLine("Printing element with index 0: " + list[0]);

            Console.WriteLine("\n---Removing some elements from the list---");
            list.RemoveAt(5);
            list.RemoveAt(0);
            list.RemoveAt(12);
            Console.WriteLine("After removing elements from the list: " + list.ToString());
            Console.WriteLine("Current list count: " + list.Count);

            Console.WriteLine("\n---Inserting some elements to the list---");
            list.InsertAt("string 5", 5);
            list.InsertAt("appear", list.Count - 1);
            list.InsertAt("string11", list.Count);
            Console.WriteLine("The new list is: " + list.ToString());
            Console.WriteLine("The new list count is: " + list.Count);

            Console.WriteLine("\n---Finding specific elements from the list---");
            Console.WriteLine("The index of 'element 9' is: " + list.Find("element 9"));
            Console.WriteLine("The index of 'element 111' is: " + list.Find("element 111"));

            Console.WriteLine("\n---Finding the maximal and the minimal element in the list---");
            Console.WriteLine("The minimal element in the list is: " + list.Min());
            Console.WriteLine("The maximal element in the list is: " + list.Max());

            Console.WriteLine("\n---Clearing the list---");
            list.Clear();
            Console.WriteLine("List count after clearing the list: " + list.Count);
            Console.WriteLine("List capacity after clearing the list: " + list.Capacity);

            // We cannot use Min() and Max() on "test" because it doesn't implement IComparable<>
            GenericList<Point2D> test = new GenericList<Point2D>();
            test.Add(new Point2D(5, 6));
            test.Add(new Point2D(-2, 1));
            test.Add(new Point2D(-12, -11));
            //test.Min();
            //test.Max()
        }
开发者ID:smihaylovit,项目名称:TelerikAcademy,代码行数:60,代码来源:GenericListTest.cs

示例9: Main

        static void Main()
        {
            //GenericList<string> test = new GenericList<string>();
            //test.AddElement("Testing");
            //test.AddElement("string");
            //Console.WriteLine(test.ToString()); //before inserting a new element
            //test.InsertAtIndex(0, "sf");
            //Console.WriteLine(test.ToString());    //after inserting a new element
            //var testAccessByIndex = test.AccessByIndex(1);
            //Console.WriteLine("I am the element at index 1 = {0}", testAccessByIndex);

           GenericList<double> anotherTest = new GenericList<double>();
           anotherTest.AddElement(1);
           anotherTest.AddElement(2);
           anotherTest.AddElement(3);
           anotherTest.AddElement(4);
          
           Console.WriteLine("Numbers = {0}", anotherTest.ToString());
           var minElement = anotherTest.Min();
           Console.WriteLine("MIN element is {0}", minElement);
           var maxElement = anotherTest.Max();
           Console.WriteLine("MAX element is {0}", maxElement);
           Console.WriteLine("Element[1] using indexer = {0}", anotherTest[1]);
           Console.WriteLine("Element AccessByIndex(1) = {0}", anotherTest.AccessByIndex(1));
           anotherTest.RemoveByIndex(1);
           Console.WriteLine("Removed element[1], result = {0}", anotherTest.ToString());
           anotherTest.InsertAtIndex(1, 5);
           Console.WriteLine("Insert 5 at index[1],result = {0}",anotherTest.ToString());
           anotherTest.ClearList();
           Console.WriteLine("Elements ClearList() = {0}", anotherTest.ToString());
           Console.WriteLine("Check if list contains 0: {0}",anotherTest.FindByValue(0));
        }
开发者ID:Alex-Bubblemaster,项目名称:C-Sharp-OOP,代码行数:32,代码来源:TestWithMain.cs

示例10: Main

        static void Main()
        {
            Path p = new Path();
            p.AddPoint(new Point3D(1, 2, 3));
            p.AddPoint(new Point3D(5, 2, 6));
            p.AddPoint(new Point3D(1, 3, 5));
            p.AddPoint(new Point3D(-5, 2, 3));
            p.AddPoint(new Point3D(-2, -10, 3));

            PathStorage.SavePath(p); //Save path in file savedPaths.txt
            Path final = PathStorage.LoadPath(); //loading from the file savedPaths.txt
            final.PrintPathList(); //printing the loaded path

            ////05, 06, 07->

            GenericList<int> list = new GenericList<int>();
            list.AddElement(10);
            list.AddElement(5);
            list.AddElement(4);
            list.InsertElement(1, 15);
            list.InsertElement(1, 12);
            Console.WriteLine(list.ToString());
            Console.WriteLine();
            list[0] = 5;
            int min = list.Min();
            int max = list.Max();
            Console.WriteLine(min);
            Console.WriteLine(max);
            list.Clear();
            Console.WriteLine(list.ToString());

            /////08, 09, 10 ->

            double[,] first = { { 0, 2, 3, 4.2 }, { 1, 2, 3, 4 }, { 1, 2, 3, 4 }, { 1, 2, 3, 4 } };
            double[,] second = { { 1, 2, 3, 4 }, { 1, 2, 3, 4 }, { 1, 2, 3, 4 }, { 1, 0, 3, 4 } };

            Matrix<double> arrFirst = new Matrix<double>(first);
            Matrix<double> arrSecond = new Matrix<double>(second);

            //checking if contain zero, return true, if not, return false if there is zero
            if (arrFirst)
            {
                Console.WriteLine("There is no zero inside");
            }
            else Console.WriteLine("There is at least one zero inside\n");
            //-----------
            Console.WriteLine("Sum of the two matrices");
            Console.WriteLine(arrFirst + arrSecond);
            Console.WriteLine("Substraction of the two matrices");
            Console.WriteLine(arrFirst - arrSecond);
            Console.WriteLine("Multiplication of the two matrices");
            Console.WriteLine(arrFirst * arrSecond);
        }
开发者ID:prestress,项目名称:Telerik_Academy_Homework_Projects,代码行数:53,代码来源:Program.cs

示例11: Main

    public static void Main()
    {
        //From Problem 1 to 4:
        Console.WriteLine(new string('=', 40));
        Console.WriteLine("Coordinates problem");
        Console.WriteLine(new string('=', 40));
        var point = new Point3D(6, 9, 72);
        var anotherPoint = new Point3D(5, 21, 4);
        var yetAnotherPoint = Point3D.StartPoint;
        double distance = CalculatingDistance.CalculateDistanceBetweenPoints(point, anotherPoint);
        Console.WriteLine("Distance between\nPoint: {0}\nPoint: {1}\nIs ==> {2:F3}", point.ToString(), anotherPoint.ToString(), distance);
        PathStorage.SavePath(anotherPoint);
        PathStorage.SavePath(point);
        PathStorage.SavePath(new Point3D(3, 5, 6));

        var listOfPoints = PathStorage.LoadPaths(@"..\..\Files\Paths.txt");
        Console.WriteLine("Paths stored in text file:");
        for (int i = 0; i < listOfPoints.Count; i++)
        {
            Console.WriteLine("Line {0, -3} : {1}", i + 1, listOfPoints[i]);
        }

        //From Problem 5 to 7:

        Console.WriteLine(new string('=', 40));
        Console.WriteLine("Now Generics");
        Console.WriteLine(new string('=', 40));
        var elementsOfStrings = new GenericList<string>();

        elementsOfStrings.Add("ABC");
        elementsOfStrings.Add("A");
        elementsOfStrings.Add("c");
        elementsOfStrings.Add("KEkE");
        elementsOfStrings.Add("HI");
        Console.WriteLine("Before:");
        Console.WriteLine(elementsOfStrings.ToString());
        Console.WriteLine("After:");
        elementsOfStrings.InsertAt(3, "Just another test!");
        elementsOfStrings.RemoveAt(0);
        Console.WriteLine(elementsOfStrings.ToString());

        var indexOfTest = elementsOfStrings.IndexOf("HI");
        var minElement = elementsOfStrings.Min();
        var maxElement = elementsOfStrings.Max();

        Console.WriteLine(@"
        IndexOf ""HI"" is {0}
        Min element is {1}
        Max element is {2}", indexOfTest, minElement, maxElement);

        elementsOfStrings.Clear();
        Console.WriteLine(new string('=', 40));
    }
开发者ID:nikistefanov,项目名称:Telerik-Academy-Homework,代码行数:53,代码来源:DefiningClassesMain.cs

示例12: Main

        public static void Main()
        {
            //Test for strings
            Console.WriteLine("Enter capacity for the list of strings");
            long capacity = long.Parse(Console.ReadLine());
            GenericList<string> listStrings = new GenericList<string>(capacity);

            listStrings.Add("Gosho");    //0
            listStrings.Add("Pesho");    //1
            listStrings.Add("Ivan");     //2
            listStrings.Add("Andrei");   //3
            listStrings.Add("Niki");     //4
            listStrings.Add("Svetlin");  //5
            Console.WriteLine(listStrings.ToString()); //Printing the list
            //Remove the element at position 0 and then move the list
            //Do the same with with 2 and then add to the position 3  a new string
            listStrings.Remove(0);
            listStrings.Remove(2);
            listStrings[3] = "Doncho";
            Console.WriteLine(listStrings.ToString()); //Printing the list
            string key = "Svetlin";
            Console.WriteLine("The string '{0}' is on position {1} on the list ", key, listStrings.FindIndex(key));
            Console.WriteLine("The min value is {0}", listStrings.Min());
            Console.WriteLine("The max value is {0}", listStrings.Max());
            listStrings.Clear();
            Console.WriteLine(listStrings.ToString()); //Printing the list
            Console.WriteLine();

            //Test with doubles
            Console.WriteLine("Enter capacity for the list of doubles");
            capacity = long.Parse(Console.ReadLine());
            GenericList<double> listDoubles = new GenericList<double>(capacity);
            listDoubles.Add(5.632);  //0
            listDoubles.Add(123.45); //1
            listDoubles.Add(-34.213);//2
            listDoubles.Add(43.1);   //3
            listDoubles.Add(4.1);    //4
            listDoubles.Add(3.1415); //5
            listDoubles.Add(2.71);   //6
            Console.WriteLine(listDoubles.ToString()); //Printing the list
            //Remove the element at position 0 and then move the list
            //Do the same with with 3 and then add to the position 3  a new string
            listDoubles.Remove(1);
            listDoubles.Remove(3);
            listDoubles[4] = 5.1;
            Console.WriteLine(listDoubles.ToString()); //Printing the list
            double key2 = 3.1415;
            Console.WriteLine("The string '{0}' is on position {1} on the list ", key2, listDoubles.FindIndex(key2));
            Console.WriteLine("The min value is {0}", listDoubles.Min());
            Console.WriteLine("The max value is {0}", listDoubles.Max());
            listDoubles.Clear();
            Console.WriteLine(listDoubles.ToString()); //Printing the list
        }
开发者ID:NikolayGenov,项目名称:TelerikAcademy,代码行数:53,代码来源:TestList.cs

示例13: Main

        static void Main()
        {
            GenericList<int> list = new GenericList<int>(10);
            for (int i = 0; i < 6; i++)
            {
                list.Add(i);
            }
            Console.WriteLine(list.ToString());
            Console.WriteLine("List state after initialization: ");
            for (int i = 0; i < list.COUNT; i++)
            {
                Console.Write("{0} ", list.GetAtIndex(i));
            }

            list.RemoveAtIndex(2);
            Console.WriteLine("\nList state after removing element at index {0}: ", list.INDEX);
            for (int i = 0; i < list.COUNT; i++)
            {
                Console.Write("{0} ", list.GetAtIndex(i));
            }

            list.InsertAtIndex(7, 13);
            Console.WriteLine("\nList state after inserting element at index {0}: ", list.INDEX);
            for (int i = 0; i < list.COUNT; i++)
            {
                Console.Write("{0} ", list.GetAtIndex(i));
            }

            list.Add(14);
            Console.WriteLine("\nList state after adding an element: ");
            for (int i = 0; i < list.COUNT; i++)
            {
                Console.Write("{0} ", list.GetAtIndex(i));
            }

            list.Add(99);
            Console.WriteLine("\nList state after adding another element: ");
            for (int i = 0; i < list.COUNT; i++)
            {
                Console.Write("{0} ", list.GetAtIndex(i));
            }

            Console.WriteLine("\n" + list.ToString());

            Console.WriteLine("MAX: {0}", GenericList<int>.Max(list));
            Console.WriteLine("MIN: {0}", GenericList<int>.Min(list));

            Console.WriteLine(list.GetAtIndex(list.GetByValue(4)));
        }
开发者ID:iliantova,项目名称:Telerik-Homework,代码行数:49,代码来源:MinAndMax.cs

示例14: AddingElements

 public void AddingElements()
 {
     GenericList<string> generic = new GenericList<string>(2);
     generic.AddElement("Pesho");
     generic.AddElement("Gosho");
     Assert.AreEqual("[Pesho, Gosho]", generic.ToString());
 }
开发者ID:abaditsegay,项目名称:SVN,代码行数:7,代码来源:UnitTest1.cs

示例15: Main

        static void Main()
        {
            GenericList<int> list = new GenericList<int>();

            list.Add(0);
            list.Add(1);
            //Console.WriteLine(list[2]);

            list.Insert(1, 4);
            list[0] = 2;
            list[2] = 3;
            //list[3] = 3;

            Console.Write("Accessing by index (list[1]): ");
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine(list[1]);
            Console.ForegroundColor = ConsoleColor.Gray;

            Console.Write("ToString(): ");
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine(list.ToString());
            Console.ForegroundColor = ConsoleColor.Gray;

            Console.Write("Min<int>(): ");
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine(list.Min<int>());
            Console.ForegroundColor = ConsoleColor.Gray;

            Console.Write("Max<int>(): ");
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine(list.Max<int>());
            Console.ForegroundColor = ConsoleColor.Gray;
        }
开发者ID:Velmond,项目名称:TelerikAcademy-CSharp,代码行数:33,代码来源:TestApplication.cs


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