示例#1
0
        static void Main(string[] args)
        {
            CityDerivedClass c1 = new CityDerivedClass();

            c1.Details();
            Console.ReadLine();
        }
示例#2
0
        static void Main(string[] args)
        {
            CityDerivedClass myDerivedCity = new CityDerivedClass("New York");

            myDerivedCity.printCityName();

            List <PersonalDetails> personalList = new List <PersonalDetails>();

            // Populate personalList
            personalList.Add(new PersonalDetails(55, "Joshpe", "Male"));
            personalList.Add(new PersonalDetails(25, "Mary", "Female"));
            personalList.Add(new PersonalDetails(10, "Lu", "Male"));
            personalList.Add(new PersonalDetails(99, "Yoda", "Male"));
            personalList.Add(new PersonalDetails(47, "Skywalker", "Male"));

            // Find all age > 35
            List <PersonalDetails> ageOver35 = personalList.FindAll(person => person.age > 35);

            // Sort by firstname
            SortByFirstName mySort = new SortByFirstName();

            personalList.Sort(mySort);

            // Create list to be merged
            List <PersonalDetails> mergePersonalList = new List <PersonalDetails>();

            // Populate mergePersonalList
            mergePersonalList.Add(new PersonalDetails(14, "Juli", "Female"));
            mergePersonalList.Add(new PersonalDetails(30, "Dacy", "Female"));
            mergePersonalList.Add(new PersonalDetails(34, "Lucy", "Female"));

            // Create list to store merged list
            List <PersonalDetails> combine = new List <PersonalDetails>();

            // Merge personalList and mergePersonalList
            combine.AddRange(personalList);
            combine.AddRange(mergePersonalList);

            // Remove all male personal from list
            personalList.RemoveAll(p => p.gender == "Male");
        }
        static void Main(string[] args)
        {
            //Inheritance Override
            Console.WriteLine("Hello World!");
            CityBaseClass c = new CityDerivedClass();

            c.VirtualMethod(1);

            //Personal Details
            List <PersonalDetails> list = new List <PersonalDetails>();

            list.Add(new PersonalDetails {
                sex = 'M', age = 32, firstName = "Deniz"
            });
            list.Add(new PersonalDetails {
                firstName = "Jason", age = 22, sex = 'M'
            });
            list.Add(new PersonalDetails {
                firstName = "Chris", age = 40, sex = 'M'
            });
            list.Add(new PersonalDetails {
                firstName = "Jennifer", age = 38, sex = 'F'
            });
            list.Add(new PersonalDetails {
                firstName = "Alex", age = 42, sex = 'M'
            });

            foreach (PersonalDetails t in list)
            {
                if (t.age > 35)
                {
                    Console.WriteLine("Age: " + t.age + ", Sex: " + t.sex + ", First Name: " + t.firstName);
                }
            }

            Console.WriteLine();
            for (int i = 0; i < list.Count - 1; i++)
            {
                for (int j = i + 1; j < list.Count; j++)
                {
                    if (string.Compare(list[i].firstName, list[j].firstName) > 0)
                    {
                        String temp = list[i].firstName;
                        list[i].firstName = list[j].firstName;
                        list[j].firstName = temp;
                    }
                }
            }

            foreach (PersonalDetails t in list)
            {
                Console.WriteLine("Age: " + t.age + ", Sex: " + t.sex + ", First Name: " + t.firstName);
            }

            List <PersonalDetails> list2 = new List <PersonalDetails>();

            list2.Add(new PersonalDetails {
                sex = 'M', age = 32, firstName = "React"
            });
            list2.Add(new PersonalDetails {
                firstName = "Fred", age = 22, sex = 'M'
            });
            list2.Add(new PersonalDetails {
                firstName = "Trevor", age = 40, sex = 'M'
            });
            list2.Add(new PersonalDetails {
                firstName = "J-lo", age = 38, sex = 'F'
            });
            list2.Add(new PersonalDetails {
                firstName = "Amblo", age = 42, sex = 'M'
            });

            list.AddRange(list2);

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].sex == 'M')
                {
                    list.RemoveAt(i);
                    i--;
                }
            }

            Console.WriteLine();
            foreach (PersonalDetails t in list)
            {
                Console.WriteLine("Age: " + t.age + ", Sex: " + t.sex + ", First Name: " + t.firstName);
            }
        }