Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            // create an object from Persons
            Persons myFriends = new Persons();

            // create a friend
            Person person1 = new Person { Firstname = "Jussi", Lastname = "Jurkka", SocialSecurityNumber = "010101-01E6" };
            Person person2 = new Person { Firstname = "Tiina", Lastname = "Ansio", SocialSecurityNumber = "011206-72A3" };
            Person person3 = new Person { Firstname = "Pera", Lastname = "Turso", SocialSecurityNumber = "210205-12N6" };

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

            // print collection
            myFriends.PrintCollection();

            // get one person
            Console.WriteLine("Get one person from collection: ");
            Person person4 = myFriends.GetPerson(0);
            if(person4 != null)
            {
                Console.WriteLine(person4.ToString());
            }
            else
            {
                Console.WriteLine("Could not find given person...");
            }

            // find person with SSID
            string socialSecurityNumber = "010101-01E6";
            Console.WriteLine("Find person with SSID: " + socialSecurityNumber);
            Person person5 = myFriends.FindPerson(socialSecurityNumber.ToString());
            if(person5 != null)
            {
                Console.WriteLine(person5.ToString());
            }
            else
            {
                Console.WriteLine("Could not find given person...");
            }

            //Console.ReadKey();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Adds a person to collection
 /// </summary>
 /// <param name="person">Added person</param>
 public void AddPerson(Person person)
 {
     persons.Add(person);
 }