private void AddHuman(List <HomoSapiens> departmentList, HomoSapiens human) { if (departmentList.Contains(human)) { Console.WriteLine($"Can't add {human} one more time."); } else { departmentList.Add(human); switch (human) { case Student student: Console.WriteLine($"Student {student.FirstName} {student.LastName} was added to the {student.Department} Department"); break; case Teacher teacher when !(teacher is HeadOfDepartment): Console.WriteLine($"Teacher {teacher.FirstName} {teacher.LastName} was added to the {teacher.Department} Department"); break; case HeadOfDepartment head: Console.WriteLine($"{human.FirstName} {human.LastName} was added to the staff as head of {head.Department} Department"); break; default: break; } } }
public void add(HomoSapiens human) { if (human != null) { humans.Add(human); } }
public static void UseDefaultConstructor() { HomoSapiens randomGuy = new HomoSapiens(); // Public member methods can still be invoked, but the information will be missing randomGuy.IntroduceMyself(); }
public HomoSapiens remove(HomoSapiens human) { if (human != null) { humans.Remove(human); } return(human); }
static void Main(string[] args) { var humano = new HomoSapiens(); var cao = new CanisFamiliaris(); var mosca = new MuscaDomestica(); Console.WriteLine(cao.GetDescricao()); }
public static void UseParameterizedConstructor() { HomoSapiens justin = new HomoSapiens("Justin", 10); justin.IntroduceMyself(); // Note that not all parameters need to be entered, as long as there is an overload for it HomoSapiens jason = new HomoSapiens("Jason"); jason.IntroduceMyself(); }
public void AddPerson(HomoSapiens newPerson) { if (newPerson == null) { throw new ArgumentNullException("newPerson"); } foreach (var person in persons) { if (person.Equals(newPerson)) { throw new ArgumentException("University already has this person", "newPerson"); } } persons.Add(newPerson); }
public void AddPeople(HomoSapiens human) { if (human == null || string.IsNullOrEmpty(human.FirstName) || string.IsNullOrEmpty(human.LastName)) { Console.WriteLine("Null people or people without name can't be added"); return; } switch (human.Department) { case UniversityDepartment.Tech: AddHuman(TechDepartment, human); break; case UniversityDepartment.Math: AddHuman(MathDepartment, human); break; case UniversityDepartment.History: AddHuman(HistoryDepartment, human); break; } }
public static double getIntelect(this HomoSapiens human) { return(human.getSoshialSkills() * 2); }
static void Main(string[] args) { NewEra newEra = new NewEra(); newEra.passCentures(); HomoSapiens h1 = new HomoSapiens(30, 242, "eg", 55, Race.Negroid); HomoSapiens h2 = new HomoSapiens(312, 242, "eg", 60, Race.Mongoloid); HomoSapiens h3 = new HomoSapiens(50, 242, "eg", 60, Race.Caucasion); HomoSapiens h4 = new HomoSapiens(50, 242, "eg", 60, Race.Negroid | Race.Mongoloid | Race.Caucasion); Console.WriteLine((Race.Negroid | Race.Caucasion | Race.Mongoloid).ToString() == Race.Multiracial.ToString()); HomoSapiens.showDevelopedPeople(); Console.WriteLine("Intelect: " + h1.getIntelect()); Console.WriteLine("My Collection"); MyCollection people = new MyCollection(); people.add(h1); people.add(h2); people.add(h3); people.sortByAge(); people.show(); try { for (int i = 0; i < 4; i++) { Australopithecus.multiply(); } } catch (MyException e) { Console.WriteLine(e.Args.Message); } Console.WriteLine(""); Console.WriteLine("Xml serialization"); Console.WriteLine(""); MyXmlSerializer serializer = new MyXmlSerializer(); serializer.xmlSerialize(); serializer.xmlDeserialize(); Console.WriteLine(""); Console.WriteLine("Binary serialization"); Console.WriteLine(""); MyBinarySerializer binSerializer = new MyBinarySerializer(); binSerializer.binarySerialize(); binSerializer.binaryDeserialize(); Console.WriteLine("GC start"); Console.WriteLine("before garbage collection: " + GC.GetTotalMemory(false)); GC.Collect(); Console.WriteLine("after garbage collection: " + GC.GetTotalMemory(true)); HomoSapiens human1 = new HomoSapiens(30, 242, "eg", 55, Race.Negroid); HomoSapiens human2 = new HomoSapiens(312, 242, "eg", 60, Race.Mongoloid); HomoSapiens human3 = new HomoSapiens(50, 242, "eg", 60, Race.Caucasion); WeakReference wr = new WeakReference(new HomoSapiens(50, 242, "eg", 60, Race.Caucasion)); human1 = null; human2 = null; Console.WriteLine("before garbage collection: " + GC.GetTotalMemory(false)); GC.Collect(); Console.WriteLine("after garbage collection: " + GC.GetTotalMemory(true)); Console.WriteLine("before garbage collection: " + GC.GetTotalMemory(false)); Meat meat = new Meat("meat", 5); meat.Dispose(); Console.WriteLine("after garbage collection: " + GC.GetTotalMemory(true)); Console.WriteLine("GC end"); Console.ReadKey(); }