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


C# GenericList.GetType方法代码示例

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


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

示例1: Main

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

            Console.WriteLine();

            myList.Add(123);
            myList.Add(1293);
            myList.Add(11);
            myList.Add(12314);
            myList.Add(111111);

            Console.WriteLine(myList);
            myList.Remove(2);
            myList.Insert(11, 2);
            myList.Insert(666, 0);
            Console.WriteLine(myList);
            Console.WriteLine(myList.Find(11));
            Console.WriteLine(myList.Contains(11121));
            myList.Add(-100);
            Console.WriteLine(myList.Min());

            Type type = myList.GetType();
            object[] allAttributes =
                type.GetCustomAttributes(false)
                .Where(x => x.GetType() == typeof (VersionAttribute))
                .ToArray();

            foreach (VersionAttribute attr in allAttributes)
            {
                Console.WriteLine(attr.Major + "." + attr.Minor);
            }
        }
开发者ID:Vallerious,项目名称:OOP-Homeworks,代码行数:33,代码来源:GenericListTester.cs

示例2: Main

        private static void Main(string[] args)
        {
            var numbers = new GenericList<int>();

            // populate the list with  numbers from 0 to 19
            Console.WriteLine("Adding numbers to the list...");
            for (var i = 0; i < 20; i++)
            {
                numbers.Add(i);
            }
            Console.WriteLine(numbers);

            // remove element at position 10
            Console.WriteLine("Removing number at position 10...");
            numbers.RemoveAt(10);
            Console.WriteLine(numbers);

            // insert a number at position 10
            Console.WriteLine("Inserting number 333 at position 10");
            numbers.Insert(10, 333);
            Console.WriteLine(numbers);

            // check if the list contains 333
            Console.WriteLine("The list contains 333: {0} ", numbers.Contains(333) ? "True" : "False");

            //accessing element by index
            Console.WriteLine("Accessing index 14");
            Console.WriteLine(numbers[14]);

            //getting the index of number 5
            Console.WriteLine("Getting the index of number 5");
            Console.WriteLine(numbers.IndexOf(5));

            //change the number at index 10 
            Console.WriteLine("Changing the number at index 10 to 555");
            numbers[10] = 555;
            Console.WriteLine(numbers);

            //clearing the numbers
            Console.WriteLine("Clearing the numbers...");
            numbers.Clear();
            Console.WriteLine(numbers);

            //Problem 4. Version
            Console.WriteLine("Version information for {0}", numbers.GetType());
            var type = typeof (GenericList<>);
            VersionAttribute versionAttr;
            foreach (Attribute attr in type.GetCustomAttributes(true))
            {
                versionAttr = attr as VersionAttribute;
                if (versionAttr != null)
                {
                    Console.WriteLine("Version of {0} : {1}", type, versionAttr.Version);
                }
            }
        }
开发者ID:KostaDinkov,项目名称:SoftUni,代码行数:56,代码来源:Program.cs

示例3: Main

 public static void Main()
 {
     var number = new GenericList<int>();
     var attributes = Attribute.GetCustomAttributes(typeof(GenericList<>));
     foreach (var attribute in attributes.OfType<VersionAttribute>())
     {
         var className = number.GetType().Name;
         Console.WriteLine("{0} class version: {1}", className, attribute.Version);
     }
 }
开发者ID:tormibg,项目名称:SoftUni-1,代码行数:10,代码来源:GenericListVersionExec.cs

示例4: Main

        // Some simple tests. They are OPTINAL.
        public static void Main()
        {
            // Create an integer list and add few elements. Also prints the size after each add.
            GenericList<int> list1 = new GenericList<int>(1);

            Console.WriteLine("Type of the list: {0}", list1.GetType());
            Console.WriteLine();

            Console.WriteLine("Current size of the list: {0}", list1.Size);
            Console.WriteLine("Current count of the elements in the list: {0}", list1.Count);
            Console.WriteLine("Adding 1 element...");
            list1.Add(1);
            Console.WriteLine("Current elements in the list:\n{0}", list1.ToString());

            Console.WriteLine("Current size of the list: {0}", list1.Size);
            Console.WriteLine("Current count of the elements in the list: {0}", list1.Count);
            Console.WriteLine("Adding 1 element...");
            list1.Add(2);
            Console.WriteLine("Current elements in the list:\n{0}", list1.ToString());

            Console.WriteLine("Current size of the list: {0}", list1.Size);
            Console.WriteLine("Current count of the elements in the list: {0}", list1.Count);
            Console.WriteLine("Adding 1 element...");
            list1.Add(3);
            Console.WriteLine("Current elements in the list:\n{0}", list1.ToString());

            Console.WriteLine("Current size of the list: {0}", list1.Size);
            Console.WriteLine("Current count of the elements in the list: {0}", list1.Count);
            Console.WriteLine();

            // Print the maximal element
            Console.WriteLine("Maximal element:");
            Console.WriteLine(list1.Max());
            Console.WriteLine();

            // Print an element by it's index
            Console.WriteLine("Printing the element at position 1 (starting from 0):\n{0}", list1[1].ToString());
            Console.WriteLine();

            // Remove an element by it's index
            Console.WriteLine("Removing the element at position 1 (starting from 0)\nand printing the result:");
            list1.RemoveAtIndex(1);

            Console.WriteLine();
            Console.WriteLine("Current size of the list: {0}", list1.Size);
            Console.WriteLine("Current count of the elements in the list: {0}", list1.Count);
            Console.WriteLine("Current elements in the list:\n{0}", list1.ToString());
            Console.WriteLine();

            // Clearing the list (the size won't change)
            Console.WriteLine("Clearing the list...");
            list1.Clear();
            Console.WriteLine("Current size of the list: {0}", list1.Size);
            Console.WriteLine("Current count of the elements in the list: {0}", list1.Count);
            Console.WriteLine("Current elements in the list:\n{0}", list1.ToString());
            Console.WriteLine();

            // Inserting an element at position 0. This will throw an exeption
            // because you can't use InsertAtIndex for empty list.
            Console.WriteLine("Exception will be thrown now...");
            list1.InsertAtIndex(0, 5);
        }
开发者ID:TishoAngelov,项目名称:TelerikAcademy,代码行数:63,代码来源:GenericListTEST.cs


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