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


C# GenericList.AccessByIndex方法代码示例

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


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

示例1: 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

示例2: Main

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

        //adding an element
        list.Add("0 - primeren");
        list.Add("1 - listttt");
        list.Add("2 - asfsdfsdfsdfd");

        //accessing element by index
        string s = list.AccessByIndex(1);
        Console.WriteLine(s);
        Console.WriteLine("------------------");

        //removing element by index
        list.RemoveAt(1);
        list.Print();
        Console.WriteLine("----------------");

        //inserting element at given position
        list.InsertAt("inserttttt", 2);
        list.Print();
        Console.WriteLine("-----------------");

        //clearing the list
        list.Clear();

        //check if the list contains a value
        list.Add("edno");
        list.Add("dve");
        list.Add("tri");

        bool b = list.Contains("dve");
        Console.WriteLine(b);
        Console.WriteLine("---------------");

        //print the entire list
        list.Print();
        Console.WriteLine("----------------");

        //auto-grow
        //GenericList<string> list3 = new GenericList<string>() { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17" };
        //list3.Print();
        //Console.WriteLine("-------------------");
        GenericList<int> list4 = new GenericList<int> {1, 2, -3, 4, 50, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};
        list4.Print();
        Console.WriteLine("--------");

        //min
        var min = list4.Min();
        Console.WriteLine(min);

        //max
        var max = list4.Max();
        Console.WriteLine(max);
        Console.WriteLine("------------");

        //Problem 4 - Generic List Version
        Type type = typeof (GenericList<>);
        object[] allAttributes = type.GetCustomAttributes(false);
        foreach (VersionAttribute attr in allAttributes)
        {
            Console.WriteLine("Version: {0}", attr.Version);
        }
    }
开发者ID:i-yotov,项目名称:Courses,代码行数:65,代码来源:Program.cs


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