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


C# GenericList.Contains方法代码示例

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


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

示例1: Main

        static void Main(string[] args)
        {
            GenericList<string> genericList = new GenericList<string>();
            genericList.Add("a");
            genericList.Add("b");
            genericList.Add("c");
            Console.WriteLine(genericList);
            Console.WriteLine("Max = {0}, Min = {1}",genericList.Max(),genericList.Min());
            Console.WriteLine("Remove b");
            genericList.Remove("b");
            Console.WriteLine(genericList);
            Console.WriteLine("genericList[0] = "+genericList.Access(0));
            Console.WriteLine("index of c = "+genericList.FindIndex("c"));
            genericList.Clear();
            genericList.Add("rom");
            genericList.Add("mon");
            genericList.Add("dom");
            Console.WriteLine(genericList);
            Console.WriteLine("Insert zom (index = 1)");
            genericList.Insert("zom",1);
            Console.WriteLine(genericList);
            Console.WriteLine(genericList.Contains("mon"));
            Console.WriteLine(genericList.Contains("aaa"));

            Type type = typeof(GenericList<>);
            object[] allAttributes = type.GetCustomAttributes(typeof(VersionAttribute), false);
            foreach (VersionAttribute attr in allAttributes)
            {
                Console.WriteLine("This class's version is {0}.", attr.Version);
            }
        }
开发者ID:ikolev94,项目名称:Homeworks,代码行数:31,代码来源:Program.cs

示例2: Main

        static void Main()
        {
            GenericList<string> glist = new GenericList<string>();
            glist.Add("First");
            glist.Add("Second");
            glist.Add("Third");
            glist.Add("Pesho");
            glist.Add("Gosho");
            glist.Add("Tosho");

            glist.Insert(0, "Purvi Pesho");

            Console.WriteLine(glist);
            Console.WriteLine("Index of \"Second\": {0}", glist.IndexOf("Second"));
            Console.WriteLine("Does contain \"Toshkata\": {0}", glist.Contains("Toshkata"));
            Console.WriteLine("Does contain \"Pesho\": {0}", glist.Contains("Pesho"));

            Console.WriteLine();

            glist.Remove(2);
            glist.Remove(2);

            Console.WriteLine(glist);
            Console.WriteLine("Min Value: {0}", glist.Min());
            Console.WriteLine("Max Value: {0}", glist.Max());

            glist.Clear();

            Console.WriteLine(glist);
        }
开发者ID:hristodobrev,项目名称:Software-University,代码行数:30,代码来源:GenericListManipulation.cs

示例3: Main

        static void Main()
        {
            GenericList<int> numbers = new GenericList<int>()
            {
                0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
            };
            Console.WriteLine("Creating a GenericList with the numbers from 1 to 20 \n {0} \n", numbers);

            numbers.Remove(19);
            Console.WriteLine("Removing the 19th element \n {0} \n", numbers);

            numbers.Add(100);
            Console.WriteLine("Adding an element to the end of the GenericList \n {0} \n", numbers);

            numbers.Insert(30, 10);
            Console.WriteLine("Inserting an element on the 10th position \n {0} \n", numbers);

            numbers[3] = 9;
            Console.WriteLine("Changing the value of the 3rd index number \n {0} \n", numbers);

            Console.WriteLine("Trying to find number 4 \n Number Found: {0}, Found At: {1} \n", numbers.Contains(4), numbers.Find(4));
            Console.WriteLine("Trying to find number 80 \n Number Found: {0}, Found At: {1} \n", numbers.Contains(80), numbers.Find(80));
            Console.WriteLine("Min element: {0}, Max element: {1} \n", numbers.Min(), numbers.Max());

            numbers.Clear();
            Console.WriteLine("Cleared GenericList: \n {0} \n", numbers);

            Type type = typeof(GenericList<>);
            VersionAttribute attribute = (VersionAttribute)type.GetCustomAttributes(false).LastOrDefault();
            Console.WriteLine("Version: " + attribute.Version);
        }
开发者ID:Bare7a,项目名称:Software-University,代码行数:31,代码来源:Program.cs

示例4: Main

 static void Main()
 {
     GenericList<int> list1 = new GenericList<int>();
     List<int> alabala=new List<int>();
     alabala.Add(1);
     list1.Add(4);
     list1.Add(5);
     list1.Add(6);
     list1.Add(1);
     list1.Add(3);
     list1.Add(2);
     Console.WriteLine("-====Printing Generic List====-");
     Console.WriteLine(list1);
     Console.WriteLine("-====End Of Printing====-");
     Console.WriteLine();
     Console.WriteLine("Min="+list1.Min());
     Console.WriteLine("Max=" + list1.Max());
     Console.WriteLine("Element in index 5 is",list1[5]);
     Console.WriteLine("Removing element on at index 2");
     list1.RemoveAtIndex(2);
     Console.WriteLine("-====Printing Generic List====-");
     Console.WriteLine(list1);
     Console.WriteLine("-====End Of Printing====-");
     Console.WriteLine();
     Console.WriteLine("Inserting element 10 on at index 5");
     list1.InsertAt(5,2);
     Console.WriteLine("-====Printing Generic List====-");
     Console.WriteLine(list1);
     Console.WriteLine("-====End Of Printing====-");
     Console.WriteLine();
     Console.WriteLine("The index of element {0} is index {1}",6,list1.IndexOf(6));
     Console.WriteLine("The List contains element 5 : {0}",list1.Contains(5));
     Console.WriteLine("The List contains element 5 : {0}", list1.Contains(50));
     Console.WriteLine("Min element of the list is {0}",list1.Min());
     Console.WriteLine("Max element of the list is {0}", list1.Max());
     Console.WriteLine("The max size of the list is {0}",list1.ActuallCapacity);
     list1.Add(4);
     list1.Add(5);
     list1.Add(6);
     list1.Add(1);
     list1.Add(3);
     list1.Add(2);
     list1.Add(5);
     list1.Add(6);
     list1.Add(1);
     list1.Add(3);
     list1.Add(2);
     Console.WriteLine("-====Printing Generic List====-");
     Console.WriteLine(list1);
     Console.WriteLine("-====End Of Printing====-");
     Console.WriteLine("The max size of the list is {0}", list1.ActuallCapacity);
 }
开发者ID:AlexanderKrustev,项目名称:SoftUni,代码行数:52,代码来源:ListExample.cs

示例5: Main

        static void Main()
        {
            GenericList<int> nums = new GenericList<int>();
            nums.Add(1);
            nums.Add(2);
            nums.Add(3);
            nums.Add(4);
            Console.WriteLine(nums[2]);
            nums.RemoveAt(1);
            nums.InsertAt(1, 2);
            Console.WriteLine(nums.IndexOf(3));
            Console.WriteLine(nums.Contains(0));
            Console.WriteLine(nums.Contains(1));
            Console.WriteLine(nums.ToString());
            Console.WriteLine(nums.Min());
            Console.WriteLine(nums.Max());

            // Testing the auto-grow functionality
            nums.Add(1);
            nums.Add(2);
            nums.Add(3);
            nums.Add(4);
            nums.Add(1);
            nums.Add(2);
            nums.Add(3);
            nums.Add(4);
            nums.Add(1);
            nums.Add(2);
            nums.Add(3);
            nums.Add(4);
            nums.Add(1);
            nums.Add(2);
            nums.Add(3);
            nums.Add(4);
            nums.Add(1);
            nums.Add(2);
            nums.Add(3);
            nums.Add(4);
            nums.Add(1);
            nums.Add(2);
            nums.Add(3);
            nums.Add(4);
            nums.Add(1);
            nums.Add(2);
            nums.Add(3);
            nums.Add(4);

            Console.WriteLine(nums.Count);
        }
开发者ID:alexxdim94,项目名称:OOP-Homeworks,代码行数:49,代码来源:GenericListTester.cs

示例6: Main

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

            list.Add(10);
            list.Add(20);
            list.Add(30);

            Console.WriteLine(list); //[10, 20, 30]
            Console.WriteLine("Max: {0}", list.Max()); //30
            Console.WriteLine("Min: {0}", list.Min()); //10

            Console.WriteLine(list[0]); //10
            Console.WriteLine(list[1]); //20

            //Exception:
            //Console.WriteLine(list[-1]);
            //Console.WriteLine(list[3]);

            list[1] = 150;
            Console.WriteLine(list);

            Console.WriteLine(list.Contains(150)); //true
            Console.WriteLine(list.Contains(1000)); //false

            Console.WriteLine(list.IndexOf(30)); //2
            Console.WriteLine(list.IndexOf(1000)); //-1

            list.InsertAtIndex(0, 1000);
            Console.WriteLine(list.ToString()); //[1000, 10, 150, 30]

            list.RemoveAtIndex(0);
            Console.WriteLine(list); //[10, 150, 30]

            //Exception:
            //list.RemoveAtIndex(-1);
            //list.RemoveAtIndex(3);
            //list.InsertAtIndex(-1, 40);
            //list.InsertAtIndex(3, 33);

            Console.WriteLine(list.Pop()); //30
            Console.WriteLine(list); //[10, 150]

            list.Push(-60);
            Console.WriteLine(list); //[10, 150, -60]

            list.Clear();
            Console.WriteLine(list); //[]
        }
开发者ID:nickgenov,项目名称:ObjectOrientedProgramming,代码行数:49,代码来源:GenericListMain.cs

示例7: Main

        static void Main()
        {
            GenericList<string> names = new GenericList<string>();
            names.ShowVersion();

            names.Add("Gosho");
            names.Add("Pesho");
            names.Add("Misho");
            names.Add("Tisho");
            names.Add("Nashmat");
            names.Add("Onufri");
            names.Add("Gencho");

            names.Insert("Tyanko", 2);
            names.Remove(1);
            //names.Clear();

            names.Add("Asen");
            names.Add("Zaro");

            Console.WriteLine("All elements: " + names);
            Console.WriteLine("Max element: " + names.Max());
            Console.WriteLine("Min element: " + names.Min());

            string search = "Onufri";
            Console.WriteLine("Elements contain {0}: {1}", search, names.Contains(search));
            Console.WriteLine("Index of {0}: {1}", search, names.IndexOf(search));
        }
开发者ID:AsenTahchiyski,项目名称:SoftUni,代码行数:28,代码来源:Program.cs

示例8: Main

        static void Main()
        {
            GenericList<int> test = new GenericList<int>(2);
            test.Add(1);
            test.Add(2);
            test.Add(10);
            test.Add(99);
            test.Add(22);
            test.Add(40);
            test.Add(121);
            test.Add(23);
            Console.WriteLine(test);
            Console.WriteLine(test[3]);
            Console.WriteLine(test.IndexOf(121));
            test.Remove(3);
            Console.WriteLine(test);
            Console.WriteLine(test[3]);
            Console.WriteLine(test.IndexOf(121));
            test.Insert(66, 4);
            Console.WriteLine(test);
            test.Insert(66, 4);
            Console.WriteLine(test);
            Console.WriteLine(test.Count);
            Console.WriteLine("Max: " + test.Max());
            Console.WriteLine("Min: " + test.Min());

            Console.WriteLine(test.Contains(121));

            Console.WriteLine();
            var allAttributes = typeof(GenericList<>).GetCustomAttributes(typeof(VersionAttribute), false);
            Console.WriteLine("Version: " + allAttributes[0]);
        }
开发者ID:ScreeM92,项目名称:Software-University,代码行数:32,代码来源:GenericListTest.cs

示例9: Main

        public static void Main()
        {
            Console.Title = "Problem 3.	Generic ";

            GenericList<int> numbers = new GenericList<int>();
            numbers.Add(5);
            numbers.Add(50);
            numbers.Add(500);
            numbers.Add(1000);

            Console.WriteLine(numbers.Max());
            Console.WriteLine(numbers.Min());

            Console.WriteLine(numbers.GetAtIndex(1));
            numbers.Insert(1, 25);
            Console.WriteLine(numbers.IndexOf(50));
            Console.WriteLine(numbers.Contains(5));
            numbers.Remove(5);
            Console.WriteLine(numbers);
            numbers.Clear();
            Console.WriteLine(numbers);

            Console.WriteLine();
            Console.WriteLine("Problem 4.	Generic List Version");
            System.Reflection.MemberInfo info = typeof(GenericList<>);
            foreach (object attribute in info.GetCustomAttributes(false))
            {
                Console.WriteLine(attribute);
            }
        }
开发者ID:Nezhdetov,项目名称:Software-University,代码行数:30,代码来源:GenericListMain.cs

示例10: Main

 public static void Main()
 {
     GenericList<int> a = new GenericList<int>();
     a.Add(15);
     a.Add(20);
     a.Add(30);
     a.Add(40);
     a.Add(55);
     a.Add(60);
     a.Add(70);
     a.Add(100);
     a.Add(100);
     Console.WriteLine(a.Capacity);
     a.Add(15);
     a[2] = 500;
     Console.WriteLine(a);
     Console.WriteLine(a.IndexOf(30));
     Console.WriteLine(a.Contains(500));
     a.InsertAt(10, 59);
     a.InsertAt(11, 59);
     a.InsertAt(12, 59);
     a.InsertAt(13, 59);
     a.InsertAt(14, 59);
     a.InsertAt(15, 59);
     a.InsertAt(16, 59);
     Console.WriteLine(a);
     Console.WriteLine(a.Capacity);
     Console.WriteLine(a.IsEmpty);
     Console.WriteLine(a.Min());
     Console.WriteLine(a.Max());
     a.Clear();
 }
开发者ID:vdonchev,项目名称:OOPOtherTypesHW,代码行数:32,代码来源:Test.cs

示例11: Main

        static void Main(string[] args)
        {
            Console.WriteLine(typeof(GenericList<>).GetCustomAttribute(typeof(Ver)));

            GenericList<string> list = new GenericList<string>();
            GenericList<Point2D> list2 = new GenericList<Point2D>();
            list2.Add(new Point2D(5, 3));
            list2.Add(new Point2D(6, 4));

            list.Add("az");
            list.Add("ti");
            list.Add("toj");
            list.Add("tq");
            list.Insert("to",1);
            list.Remove(3);

            for (int i = 0; i < list.Count; i++)
            {
                Console.WriteLine(list[i]);
            }

            Console.WriteLine(Environment.NewLine);
            Console.WriteLine(list.FindIndexOf("toj"));
            Console.WriteLine(list);
            Console.WriteLine(list.Contains("tq"));
            Console.WriteLine(list.Max());
            Console.WriteLine(list2.Max());
            Console.WriteLine(list2.Contains(new Point2D(5, 3)));
            Console.WriteLine(list2.Contains(new Point2D(5, 2)));
        }
开发者ID:EBojilova,项目名称:SoftUni-3,代码行数:30,代码来源:Program.cs

示例12: Main

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

            intList.AddRange(Enumerable.Range(1, 30).ToArray());

            Console.WriteLine("Number of elements: {0}", intList.Count);
            Console.WriteLine(intList);

            Console.WriteLine($"List contains 7: {intList.Contains(7)}");
            Console.WriteLine($"Index of 12: {intList.IndexOf(12)}");

            Console.WriteLine();

            var stringList = new GenericList<string>
            {
                "C#",
                "Java",
                "PHP",
                "SQL"
            };

            Console.WriteLine($"Number of elements: {stringList.Count}");
            Console.WriteLine(stringList);

            Console.WriteLine($"List contains \"Java\": {stringList.Contains("Java")}");
        }
开发者ID:HouseBreaker,项目名称:OOP,代码行数:27,代码来源:GenericListMain.cs

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

示例14: Main

    static void Main()
    {
        GenericList<int> nums = new GenericList<int>() { 1, 2, 5, 7 };
        Console.WriteLine("All elements: " + nums.ToString());

        Console.WriteLine("Num at index 1: " + nums[1]);
        nums.Remove(0);
        Console.WriteLine("Element at index 0 has been removed");
        Console.WriteLine("Num at index 1: " + nums[1]);
        Console.WriteLine("The index of 5 is: " + nums.Find(5));
        Console.WriteLine("Nums contains 7? " + nums.Contains(7));
        for (int index = 0; index < 50; index++)
        {
            nums.Add(9);
            Console.Write("Element added: " + nums[nums.Count - 1]);
            Console.WriteLine(" Count: " + nums.Count + " Capacity: " + nums.Capacity);
        }
        nums.Insert(14, 0);
        nums.Insert(14, 0);
        nums.Insert(14, 0);
        nums.Insert(20, 20);
        Console.WriteLine(nums);
        Console.WriteLine("Min: " + nums.Min());
        Console.WriteLine("Max: " + nums.Max());

        Console.WriteLine("The version of this class is: " + nums.Version());
    }
开发者ID:shnogeorgiev,项目名称:Software-University-Courses,代码行数:27,代码来源:GenericListDemo.cs

示例15: Main

        static void Main()
        {
            GenericList<int> nums = new GenericList<int>();
            nums.Add(5);
            nums.Add(10);
            nums.Add(50);

            Console.WriteLine(nums.Contains(10)); // output: True
            Console.WriteLine(nums[2]);           // output: 50

            nums[2] = 42;
            Console.WriteLine(nums[2]);           // output: 42

            Console.WriteLine(nums.IndexOf(42));  // output: 2

            Console.WriteLine(nums.Count);        // output: 3

            Console.WriteLine(nums);              // output: [item1, item2...]

            nums.RemoveAt(0);
            Console.WriteLine(nums.Count);        // output: 2

            nums.Clear();
            Console.WriteLine(nums.Count);        // output: 0
        }
开发者ID:msmilkoff,项目名称:OOPHomeworks,代码行数:25,代码来源:MainClass.cs


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