예제 #1
0
파일: Persons.cs 프로젝트: petar-rusev/OOP
 static void Main(string[] args)
 {
     Console.WriteLine("Please enter your name:");
     string name = Console.ReadLine();
     if (name == string.Empty)
     {
         throw new ArgumentException("Invalid name: The name must not be empy field!");
     }
     Console.WriteLine("Please enter your age:");
     int age = int.Parse(Console.ReadLine());
     if (age < 1 || age > 100)
     {
         throw new ArgumentException("Invalid age: The age must be in range 1-100");
     }
     Console.WriteLine("Please enter your email:");
     string email = Console.ReadLine();
     string pat = @"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$";
     Regex reg = new Regex(pat);
     Match match = reg.Match(email);
     if (email != string.Empty && match.Success == false)
     {
         throw new ArgumentException("Invalid Argument: The email must be null or non-empty string containing @");
     }
     Person man = new Person(name, age, email);
     Console.WriteLine(man.ToString());
 }
예제 #2
0
 public void AddMember(Person member)
 {
     this.members.Add(member);
 }
예제 #3
0
 public void AddMember(Person member)
 {
     People.Add(member);
 }
예제 #4
0
        public static void Main()
        {
            List <Person> familyTree = new List <Person>();
            List <string> ties       = new List <string>();

            string nameOrBirthday = Console.ReadLine();

            string personInformation;

            while ((personInformation = Console.ReadLine()) != "End")
            {
                string[] tokens = personInformation.Split(" - ", StringSplitOptions.RemoveEmptyEntries);

                if (tokens.Length == 1)
                {
                    string[] parts    = personInformation.Split(" ", StringSplitOptions.RemoveEmptyEntries);
                    string   name     = $"{parts[0]} {parts[1]}";
                    string   birthday = parts[2];
                    Person   person   = new Person(name, birthday);
                    familyTree.Add(person);
                }
                else
                {
                    ties.Add(personInformation);
                }
            }

            foreach (string tie in ties)
            {
                Person parent = new Person();
                Person child  = new Person();

                string[] parts = tie.Split(" - ", StringSplitOptions.RemoveEmptyEntries);
                if (parts[0].Contains("/") && parts[1].Contains("/"))
                {
                    string parentBirthday = parts[0];
                    string childBirthday  = parts[1];

                    parent = familyTree.First(p => p.Birthday == parentBirthday);
                    child  = familyTree.First(p => p.Birthday == childBirthday);
                }
                else if (parts[0].Contains("/") || parts[1].Contains("/"))
                {
                    if (parts[0].Contains("/"))
                    {
                        string birthday = parts[0];
                        string name     = parts[1];

                        parent = familyTree.First(p => p.Birthday == birthday);
                        child  = familyTree.First(p => p.Name == name);
                    }
                    else
                    {
                        string birthday = parts[1];
                        string name     = parts[0];

                        parent = familyTree.First(p => p.Name == name);
                        child  = familyTree.First(p => p.Birthday == birthday);
                    }
                }
                else
                {
                    string parentName = parts[0];
                    string childName  = parts[1];

                    parent = familyTree.First(p => p.Name == parentName);
                    child  = familyTree.First(p => p.Name == childName);
                }

                if (parent.Children.Contains(child) == false)
                {
                    parent.Children.Add(child);
                }

                if (parent.Parents.Contains(parent) == false)
                {
                    child.Parents.Add(parent);
                }
            }

            Person targetPerson = new Person();

            if (nameOrBirthday.Contains("/"))
            {
                targetPerson = familyTree.First(p => p.Birthday == nameOrBirthday);
            }
            else
            {
                targetPerson = familyTree.First(p => p.Name == nameOrBirthday);
            }

            Console.WriteLine(targetPerson);
        }
예제 #5
0
 public void AddMemeber(Person member)
 {
     this.family.Add(member);
 }
예제 #6
0
 public static void Main(string[] args)
 {
     Person p = new Person("Ivan", 10);
 }
예제 #7
0
 public static void AddMemberToDictionary(Person currentPerson)
 {
     Members[currentPerson.Name] = currentPerson.Age;
 }
예제 #8
0
 static void Main(string[] args)
 {
     Person peter  = new Person();
     Person georgi = new Person(18);
     Person stamo  = new Person("Stamat", 43);
 }