Пример #1
0
        static void Main(string[] args)
        {
            // Create an object from Persons
            Persons myFriends = new Persons();

            // Create friends...
            Person person1 = new Person { Firstname = "Jussi", Lastname = "Jurkka", SocialSecurityNumber = "010101-010E" };
            Person person2 = new Person { Firstname = "Elmo", Lastname = "Tohtori", SocialSecurityNumber = "020202-020B" };
            Person person3 = new Person { Firstname = "Nuikki", Lastname = "Professori", SocialSecurityNumber = "030303-030D" };

            // Add persons to collection
            myFriends.AddPerson(person1);
            myFriends.AddPerson(person2);
            myFriends.AddPerson(person3);

            // Print collection
            myFriends.PrintCollection();

            // Get one person
            Console.WriteLine();
            Console.WriteLine("Get one person from collection:");
            Person person4 = myFriends.GetPerson(2);
            if (person4 != null)
            {
                Console.WriteLine(person4.ToString());
            } else
            {
                Console.WriteLine("Cannot find person in that position...");
            }

            // Find person with sotu
            Console.WriteLine();
            string socialSecurityNumber = "010101-010E";
            Console.WriteLine("Find person with sotu: ");
            Person person5 = myFriends.FindPerson(socialSecurityNumber);
            if (person5 != null)
            {
                Console.WriteLine(person5.ToString());
            } else
            {
                Console.WriteLine("Not found...");
            }

        }
Пример #2
0
 /// <summary>
 /// Adds a person to collection
 /// </summary>
 /// <param name="person">Added person</param>
 public void AddPerson(Person person)
 {
     persons.Add(person);
 }