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

            //create a few friends
            Person person1 = new Person { Firstname="Jussi",  Lastname="Jurkka",SocialSecurityNumber="010101-01E6" };
            Person person2= new Person { Firstname = "Matti", Lastname = "Virtanen", SocialSecurityNumber = "020202-02F7" };
            Person person3 = new Person { Firstname = "Pekka", Lastname = "Olli", SocialSecurityNumber = "030303-03G8" };

            //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(1);
            if (person4 != null)
            {
                Console.WriteLine(person4.ToString());
            }
            else
            {
                Console.WriteLine("Cannot find person in that position.");
            }

            //find person with ssn 
            string socialSecurityNumber = "010101-01E6";
            Console.WriteLine("Find person with ssn: " + socialSecurityNumber);
            Person person5 = myFriends.FindPerson(socialSecurityNumber);
            if (person5!=null)
            {
                Console.WriteLine(person5.ToString());
            }
            else
            {
                Console.WriteLine("Person not found.");
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Method adds a person to collection
 /// </summary>
 /// <param name="person">Added person</param>
 public void AddPerson(Person person)
 {
     persons.Add(person);
 }